rubencit
New Member
- Messages
- 28
- Reaction score
- 1
- Points
- 0
In this example we create a table named test with three fields: an ID field, which will serve to uniquely identify a row with the value of that field, another field with the name of a person and finally a field with the name of the person .
To create the table you can use the MySQL administration tool on your web server or you can write a text file with the contents of the corresponding SQL statement and then tell the database engine that runs with the following statement:
mysql-u root base_datos <prueba.sql
prueba.sql
CREATE TABLE test (
ID_Prueba int (11) DEFAULT '0 'NOT NULL auto_increment,
Name varchar (100)
Surname varchar (100)
PRIMARY KEY (ID_Prueba)
UNIQUE ID_Prueba (ID_Prueba)
);
<?php
function Conectarse()
{
if (!($link=mysql_connect("localhost","usuario","Password")))
{
echo "Error connecting to database.";
exit();
}
if (!mysql_select_db("base_datos",$link))
{
echo "Error selecting the database.";
exit();
}
return $link;
}
$link=Conectarse();
echo "Connecting to the database obtained.<br>";
mysql_close($link);
?>
To create the table you can use the MySQL administration tool on your web server or you can write a text file with the contents of the corresponding SQL statement and then tell the database engine that runs with the following statement:
mysql-u root base_datos <prueba.sql
prueba.sql
CREATE TABLE test (
ID_Prueba int (11) DEFAULT '0 'NOT NULL auto_increment,
Name varchar (100)
Surname varchar (100)
PRIMARY KEY (ID_Prueba)
UNIQUE ID_Prueba (ID_Prueba)
);
<?php
function Conectarse()
{
if (!($link=mysql_connect("localhost","usuario","Password")))
{
echo "Error connecting to database.";
exit();
}
if (!mysql_select_db("base_datos",$link))
{
echo "Error selecting the database.";
exit();
}
return $link;
}
$link=Conectarse();
echo "Connecting to the database obtained.<br>";
mysql_close($link);
?>