title: PHP PDO Inserting Data
body: <p>I am new with PDO and I am trying to insert data into a table.</p>
  
  <p>This is the table I have:</p>
  
  <pre><code>CREATE TABLE  `Message` (
  `ID` INT( 8 ) NOT NULL  AUTO_INCREMENT ,
  `DateTime` DATETIME NOT NULL ,
  `SmsSid` VARCHAR( 34 ) NOT NULL ,
  `AccountSid` VARCHAR( 34 ) NOT NULL ,
  `From` VARCHAR( 12 ) NOT NULL ,
  `To` VARCHAR( 12 ) NOT NULL ,
  `Body` VARCHAR( 160 ) NOT NULL ,
  `FromCity` VARCHAR( 50 ) NULL ,
  `FromState` VARCHAR( 50 ) NULL ,
  `FromZip` VARCHAR( 50 ) NULL ,
  `FromCountry` VARCHAR( 50 ) NULL ,
  `ToCity` VARCHAR( 50 ) NULL ,
  `ToState` VARCHAR( 50 ) NULL ,
  `ToZip` VARCHAR( 50 ) NULL ,
  `ToCountry` VARCHAR( 50 ) NULL ,
  `ConversationNumber` INT( 4 ) NOT NULL ,
  PRIMARY KEY (  `ID` )
  ) ENGINE = MYISAM
  </code></pre>
  
  <p>This is the PHP Code where I'm trying to insert into the table.  What is the proper way to do this insert statement? prepare() query() exec()?</p>
  
  <p>I am able to insert into a less complex table by using this similar code but not this one above.  I'm unsure what exactly is causing the problem, syntax, column types, auto increment, datetime? Is there something with this table that I'm not handling right in the insert query? Also am I handling exceptions/error handling correctly to see the proper error messages I'd need to help debug?  </p>
  
  <pre><code>&lt;?php
  try
  {
  $connectionString = new PDO("mysql:host=xxxx;dbname=xxxx;","xxxx","xxxx");
  }
  catch(PDOException $e)
  {
  echo 'Connection failed'.$e-&gt;getMessage();
  }
  
  $DateTime = "NOW()";
  $SmsSid = "abcdef";
  $AccountSid = "abcdef";
  $FromWho = "abcdef";
  $To = "abcdef";
  $Body = "abcdef";
  $FromCity = "abcdef";
  $FromState = "abcdef";
  $FromZip = "abcdef";
  $FromCountry = "abcdef";
  $ToCity = "abcdef";
  $ToState = "abcdef";
  $ToZip = "abcdef";
  $ToCountry = "abcdef";
  $ConversationNumber = "abcdef";
  
  try
  {
  $executeQuery = $connectionString-&gt;prepare("INSERT INTO Message (SmsSid,AccountSid,`From`,To,Body,FromCity,FromState,FromZip,FromCountry,ToCity,ToState,ToZip,ToCountry,ConversationNumber) VALUES (:SmsSid,:AccountSid,:FromWho,:To,:Body,:FromCity,:FromState,:FromZip,:FromCountry,:ToCity,:ToState,:ToZip,:ToCountry,:ConversationNumber)");
  
  $executeQuery-&gt;execute(array(':SmsSid'=&gt;$SmsSid,':AccountSid'=&gt;$AccountSid,':FromWho'=&gt;$FromWho,':To'=&gt;$To,':Body'=&gt;$Body,':FromCity'=&gt;$FromCity,':FromState'=&gt;$FromState,':FromZip'=&gt;$FromZip,':FromCountry'=&gt;$FromCountry,':ToCity'=&gt;$ToCity,':ToState'=&gt;$ToState,':ToZip'=&gt;$ToZip,':ToCountry'=&gt;$ToCountry,':ConversationNumber'=&gt;$ConversationNumber));
  
  
  }
  catch(PDOException $e)
  {
  echo 'Query failed'.$e-&gt;getMessage();
  }
  
  $connectionString = null;
  ?&gt;
  </code></pre>