ID: 39143 Updated by: [EMAIL PROTECTED] Reported By: aspen dot olmsted at alliance dot biz -Status: Open +Status: Bogus Bug Type: PDO related Operating System: Windows XP SP2 PHP Version: 5CVS-2006-10-13 (snap) New Comment:
This cannot work. A replacement parameter is not to replace parts of the SQL code, it is for setting data values before execution. Databases that support it will compile the code before execution which then will generate a speedup when the same statement is called more often with different data values. So: A replacement parameter must resove to data not a sql fragment. In your example the following SQL is executed after replacement: insert into pdotest(Code,Description) VALUES ('dbo.pdo_getcode(26050)','test') This will fail. A correct statement would be with a data parameter, e.g.: $a[Code] = 26050; $a[Description] = 'test'; $stmt = $dbh->prepare("insert into pdotest(Code,Description) VALUES (dbo.pdo_getcode(:Code),:Description)"); $x = $stmt->execute($a); $stmt = null; Previous Comments: ------------------------------------------------------------------------ [2006-10-13 02:43:51] aspen dot olmsted at alliance dot biz Description: ------------ If you try to insert a record using MSSQL, ODBC, PDO and windows with a replacement parameter that is a db function it will fail. The same insert can be written without replacement parameters using both exec and prepare. Reproduce code: --------------- SQL Table: CREATE TABLE [pdotest] ( [Code] [int] NOT NULL , [Description] [varchar] (100) ) ON [PRIMARY] GO SQL Function: CREATE FUNCTION dbo.pdo_GetCode (@inCode int) RETURNS int AS BEGIN return @incode END $a[Code] = 'dbo.pdo_getcode(26050)'; $a[Description] = 'test'; $stmt = $dbh->prepare("insert into pdotest(Code,Description) VALUES (:Code,:Description)"); $x = $stmt->execute($a); $stmt = null; $stmt = $dbh->prepare("insert into pdotest(Code,Description) VALUES (dbo.pdo_getcode(26050),'test')"); $x = $stmt->execute(); $stmt = null; $x = $dbh->exec("insert into pdotest(Code,Description) VALUES (dbo.pdo_getcode(26050),'test')"); Expected result: ---------------- With the above code all three methods should insert a record Actual result: -------------- The first method fails with the replacement parameters and the other two pass. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=39143&edit=1