Error binding date parameter to prepared statement - Using PHP PDO / ODBC with SQL Server

I have a pdo connection with ODBC (v2000.86.359.00) connected to a SQL Server database (v8.00.2039 SP4 Standard Edition).

It works:

$id = 486;
$duedate = 'June 27, 2012';
$query ="INSERT into AssetHistory (AssetID, DateDue) Values($id, $duedate);";                   
$noParams = $db->exec($query);
$db->query($query);

But if I try to use a prepared statement as follows:

$sql = 'INSERT into AssetHistory 
    (AssetID, DateDue)
    Values(:id, :duedate);';                

$input = array(':id'=>486, ':duedate'=>'June 27, 2012');
$smt = $db->prepare($sql);
$smt->execute($input);

I get this error (from $ smt-> errorInfo ()):

 "[Microsoft][ODBC Driver Manager] Function sequence error (SQLExecute[0] at ext\pdo_odbc\odbc_stmt.c:254)"

I tried: 1) Attachment: duedate in single quotes 2) Binding date to timestamp unix unit 3) Binding: duedate to php DateTime object 4) Inserting all $ duedate into sql statement before preparation

At this point, I can get stuck using the $ db-> request method and sanitize the input as much as possible, but I would really appreciate any suggestions.

Using PHP 5.38 in a Windows Server 2003 window.

: . , .

:

$smt->bindValue(':id', 486, PDO::PARAM_INT);
$smt->bindValue(':duedate', 'June 27, 2012', PDO::PARAM_STR);

sql, :

$sql = 'INSERT into AssetHistory 
   (AssetID, DateDue)
Values(:id, convert(datetime,:duedate, 100));';

:    " COUNT "

, SQL Server unix...

+5
3

, , sqlsrv php drivers ( 2.0) SQL Server 2008.

$dsn - , .

php_pdo_sqlsrv_53_ts_vc9.dll, , /- , DLL php.ini .

+3

strtotime?

 $phpdate = strtotime( $duedate);

SQL CONVERT

 convert(datetime, :duedate, 100)

SQL datetime, ?

:

array(':id'=>486, ':borrower'=> 'name', ':loaner'=>'KOPERW', ':duedate'=>strtotime($duedate),

array(':id'=>486, ':borrower'=> 'name', ':loaner'=>'KOPERW', ':duedate"=>$duedate),"0000-00-00 00:00:00"
+1

" COUNT " , , .

.

0

All Articles