?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


?

Previous Page Page 3 of 5 Next Page

Create A Table

Even if you have a table setup, read this section to see how to connect to a database and execute an SQL query.

We will create a table that holds email information for a person.

PHP Code:


$connection = mysql_connect ("", "", "");
if ($connection == false){
??echo mysql_errno().": ".mysql_error()."
";
??exit;
} ??

$query = "create table email_info " .
???????"(fullname varchar(255), email_address varchar(255))";
$result = mysql_db_query ("test_database", $query);

if ($result)
??echo "Table 'email_info' was successfully created!";
else
??echo mysql_errno().": ".mysql_error()."
";

mysql_close ();


?>

In order to work with MySQL we have to open a connection.? The syntax is mysql_connect (mysql_host, mysql_username, mysql_password).? By specifying nothing, we connect to the local host MySQL database and open a connection as the default user.? If you want to log in as a certain user to a certain MySQL host then enter your settings.

We specify the database, by passing "test_database" as the first parameter in the mysql_db_query function call.

Now, we can interact with the database.? We will create a table so we can store individual records.? For the table email_info, we delegate two fields.? One to hold the full name (e.g. 'Kris Arndt') and another to hold the email address (e.g. '[email protected]').

Previous Page Page 3 of 5 Next Page