Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


7,904 questions

11,012 answers

573 users

How to create a table with SQL in MySQL database with PHP Data Objects (PDO) in PHP

1 Answer

0 votes
$db_host = 'localhost';
$db_user = 'user';
$db_password = 'password';
$db_name = 'database_name';
try 
{
  $con = new PDO("mysql:host=".$db_host.";dbname=".$db_name, $db_user, $db_password);           
  $sql = "CREATE TABLE Workers
         (
           WorkerID int(7) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
           FirstName varchar(255) NOT NULL,
           LastName varchar(255) NOT NULL,
           URL varchar(255) UNIQUE,
           Salary float DEFAULT 0,
           StartWorkingDate TIMESTAMP
         )";
  $con->exec($sql);
}
catch (PDOException $e) 
{
   echo "Error: " . $e->getMessage();
}

 




answered Sep 24, 2015 by avibootz
...