title: Problems automatically creating a mysql database so it can be used on a fresh computer using PHP
body: <p>I am trying to automatically create the database and table so the website i am creating can be used on a fresh version of XXAMP. At the moment I used PHP myadmin to create the table. however when it loads on a fresh version of XXAMP the database will not be saved on the fresh computer. Therefore im trying to create PHP to automatically create the database and table so content can be added. This is my attempt at the moment but it doesn't seem to be working. Can anyone push me in the right direction?</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "root";
  $password = "";
  $dbname = "contentdatabase";
  
  try {
      $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
      // set the PDO error mode to exception
      $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
      // sql to create table
      $sql = "CREATE TABLE items
      id INT(10) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
      itemName text NULL,
      itemDescription text NULL,
      itemPrice float NULL,
      itemStock smallint(6) NULL,
      itemImage VARCHAR(100)  NULL,
      )";
  
      // use exec() because no results are returned
      $conn-&gt;exec($sql);
      echo "Table items created successfully";
      }
  catch(PDOException $e)
      {
      echo $sql . "&lt;br&gt;" . $e-&gt;getMessage();
      }
  
  $conn = null;
  ?&gt;
  </code></pre>