How to insert CURDATE() with Slim-PDO?


#1

Hello all!
How I can insert with Slim-PDO CURDATE()?

$insertStatement = $obj->pdo->insert(array('id', ......., 'collected_on'))
    ->into('test')
    ->values(array($test['id'], ......, CURDATE()));

Fatal error: Uncaught Error: Call to undefined function CURDATE()

And how I can real_escape_string with Slim-PDO? Or Slim-PDO do it automatically?

Tnx


#2

CURDATE() is a MySQL function, not a PHP or SLIM built in.

$insertStatement = $obj->pdo->insert(array('id', ......., CURDATE() ))
->into('test')
->values(array($test['id'], ......));

Put it into the query.


#3

Thank you for answer, but now I have

Fatal error: Uncaught PDOException: SQLSTATE[21S01]: Insert value list does not match column list: 1136 Column count doesn’t match value count at row

And how about real_escape_string?


#4

The error is incredibly easy to fix: “Insert value list does not match column list: 1136 Column count doesn’t match value count at row”, you’re passing more or lass parameters than mysql expects.

Please use PDO Prepared Statement instead of real_escape_string.