[Solved] PDO Insert error on execute


Looks like your DSN is incorrect (you have a space in it). Try this PDO constructor and stop using or die()!

$db = new PDO('mysql:host=localhost;dbname=xxxxxx;charset=utf8', 'yyyyyy', 'zzzzzz', array(
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_EMULATE_PREPARES   => false,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC));

$query = "INSERT INTO multiTicker (mtgox,btcstamp,btce,btcchina,myDateTime) VALUES (:mtgox,:btcstamp,:btce,:btcchina,:myDateTime)";
$st = $db->prepare($query);
$st->execute(array(
    ':mtgox' => $mtgox,
    ':btcstamp' => $btcstamp,
    ':btce' => $btce,
    ':btcchina' => $btcchina,
    ':myDateTime' => $myDateTime
));

You don’t have to set the default fetch mode to PDO::FETCH_ASSOC but I find it’s handy.

1

solved PDO Insert error on execute