Learning PHP and MySQL

Example 12-1 Creating a table from a PHP page in create_table.php

<?php include('db_login.php'); require_once(  'DB.php'  );
$connection  =  DB::connect(  "mysql://$db_username:$db_password@$db_host/
$db_database");
if  (!
$connection)
{
die  ("Could  not  connect  to  the  database:  <br>".  DB::errorMessage());
};
$query  =  '
CREATE  TABLE  `purchases`  (
`purchase_id`  int(11)  NOT  NULL  auto_increment,
`user_id`  varchar(10)  NOT  NULL,
`title_id`  int(11)  NOT  NULL,
`purchased`  timestamp  NOT  NULL, PRIMARY  KEY    (`purchase_id`)
)
'
;
echo  (
"Table  created  successfully!");
$result  =  $connection->query($query);
if  (
DB::isError($result))
{
die  ("Could  not  query  the  database:  <br>".  $query.  "  ".DB::errorMessage($result));
}
$connection
->disconnect();
?>

Posted by on 09/25 at 10:50 AM

Next entry: Example 12-2 Dropping the purchases table in drop.php

Previous entry: Example 11-29 Executing df and displaying the results

<< Back to main