title: PDO execute in PHP
body: <p>Iam having some trouble with a PDO execute statement. My code looks like this:</p>
  
  <pre><code>try {
  
      $stmt = $this-&gt;dbh-&gt;prepare("INSERT INTO smtp_servers (host, port, ssl, auth, username, password) VALUES(:host, :port, :ssl, :auth, :username, :password)");
      $stmt-&gt;bindParam(':host', $serverOptions[0]);
      $stmt-&gt;bindParam(':port', $serverOptions[1]);
      $stmt-&gt;bindParam(':ssl', $serverOptions[2]);
      $stmt-&gt;bindParam(':auth', $serverOptions[3]);
      $stmt-&gt;bindParam(':username', $serverOptions[4]);
      $stmt-&gt;bindParam(':password', $serverOptions[5]);
      $stmt-&gt;execute();
  
  } catch (PDOException $e) {
      print("fail");
  }
  </code></pre>
  
  <p>It dosen't print "fail" if i make a print before the <code>$stmt-&gt;execute();</code> it prints the test, but if i make a print just after the execute line, it dosen't print the text.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>UPDATED:</strong></p>
  
  <p>I tried to throw the more generic Exception, without any luck, i implemented <code>PDO::PARAM_INT</code> where i am using integers. And also added the line:</p>
  
  <pre><code>$this-&gt;dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  </code></pre>
  
  <p>Now my code looks like this:</p>
  
  <pre><code>try {
  
      $stmt = $this-&gt;dbh-&gt;prepare("INSERT INTO smtp_servers (host, port, ssl, auth, username, password) VALUES(:host, :port, :ssl, :auth, :username, :password)");
      $stmt-&gt;bindParam(':host', $serverOptions[0]);
      $stmt-&gt;bindParam(':port', $serverOptions[1], PDO::PARAM_INT);
      $stmt-&gt;bindParam(':ssl', $serverOptions[2], PDO::PARAM_INT);
      $stmt-&gt;bindParam(':auth', $serverOptions[3], PDO::PARAM_INT);
      $stmt-&gt;bindParam(':username', $serverOptions[4]);
      $stmt-&gt;bindParam(':password', $serverOptions[5]);
      $stmt-&gt;execute();
  
  } catch (PDOException $e) {
      debug("fail");
  }
  </code></pre>
  
  <p>I quess it would help to see my db table design?</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `smtp_servers` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `host` varchar(50) NOT NULL,
    `port` int(11) DEFAULT NULL,
    `ssl` smallint(11) DEFAULT NULL,
    `auth` smallint(11) DEFAULT NULL,
    `username` varchar(50) DEFAULT NULL,
    `password` varchar(50) DEFAULT NULL,
    PRIMARY KEY (`id`)
  ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
  </code></pre>
  
  <p>Now i am getting this error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ssl, auth, username, password FROM smtp_servers' at line 1' in /var/www/isms/php/communication/Mail.php on line 13 PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ssl, auth, username, password FROM smtp_servers' at line 1 in /var/www/isms/php/communication/Mail.php on line 13 Call Stack: 0.0002 649056 1. {main}() /var/www/isms/index.php:0 0.0023 867336 2. include('/var/www/isms/php/settings/ismsSettings.php') /var/www/isms/index.php:88 0.0065 1091712 3. require_once('/var/www/isms/php/settings/MailSettings.php') /var/www/isms/php/settings/ismsSettings.php:29 0.0147 2288960 4. require_once('/var/www/isms/php/forms/settings/EditSmtpServer.php') /var/www/isms/php/settings/MailSettings.php:4 0.0155 2290456 5. Mail->getServers() /var/www/isms/php/forms/settings/EditSmtpServer.php:41 0.0156 2291888 6. PDOStatement->execute() /var/www/isms/php/communication/Mail.php:13</p>
  </blockquote>