0
votes

I have code that looks something like this:

$cmd = new com('ADODB.command');
$cmd->activeConnection = $CONNECTION;
$sql = 'UPDATE MyTable SET WhenPlanned = ? WHERE ID = ?';
$cmd->commandText = $sql;
$p1 = $cmd->createParameter('WhenPlanned', adDate, adParamInput, 0, $dateVal)
$p2 = $cmd->createParameter('ID', adInteger, adParamInput, 4, $intVal); 
$cmd->parameters->append($p1);
$cmd->parameters->append($p2);
$cmd->execute();

This only produces the following error: PHP Fatal error: Uncaught exception 'com_exception' with message 'Source: ADODB.Command Description: Application uses a value of the wrong type for the current operation.'

The $dateVal variable is a string representation of a date. I've tried creating a PHP datetime object to pass to no avail...Does anyone know how to pass in a date that the ADO Parameter will accept as an argument in PHP? Thanks!

1
I would imagine you would need to actually prepare the statement somewhere? - Mike Brant
Hi, Mike. I left out a line specifying the commandText value in my example. - user3271228

1 Answers

0
votes

I created a test table to isolate and experiment with date parameters and found something that worked. I guess it's a date formatting issue. I was passing in dates that looked like the string in the date() function below without formatting.

$cmd = new com('ADODB.command');
$cmd->activeConnection = $CONNECTION[SYSTEM];
$sql = 'INSERT INTO TestDateTable (testdate) VALUES (?)';
$cmd->commandText = $sql;
$d = date('Y-m-d H:i:s', strtotime('10/26/2015'));
$p1 = $cmd->createParameter('testdate', adDate, adParamInput, 0,  $d);
$cmd->parameters->append($p1);
$cmd->execute();

This successfully inserted a date in my table.