I am experiencing problems while inserting date type value in mysql using PDO
code snippet :
$HOST = 'localhost';
$DATABASE = 'db';
$USERNAME = 'XXXXXX';
$PASSWORD = 'XXXXXX';
$DBH = new PDO("mysql:host=$HOST;dbname=$DATABASE;charset=utf8",$USERNAME,$PASSWORD);
$DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$incomingdate = date('Y-m-d', time()); // this echoes 2013-07-03
$name = "XYZ";
try {
$stmt = $DBH->query('INSERT INTO tablename (date ,name ) VALUES (?, ?)');
$stmt->execute(array($incomingdate, $name ));
$row_count = $stmt->rowCount();
echo $row_count.' rows selected';
}
catch(PDOException $e ){
echo 'Error in executing query ...';
file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);
}
Datatype at the mysql database side of date column is : DATE
Error : Below is the contents of PDOErrors.txt SQLSTATE[HY000]: General error: 2031
What is wrong with this query....earlier query ran smooth when i used mysql_* functions ... so what is wrong with prepared statements ??? And also .... what should be done if datatype is of Timestamp type and / or datetime type at the mysql end