|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-08-27 03:35 UTC] eprayner at gmail dot com
[2009-09-18 08:19 UTC] uw@php.net
[2009-09-18 10:46 UTC] eprayner at gmail dot com
[2009-09-18 12:42 UTC] uw@php.net
[2009-09-18 15:35 UTC] eprayner at gmail dot com
[2009-09-18 16:21 UTC] uw@php.net
[2009-09-23 15:59 UTC] sjoerd@php.net
[2009-09-23 23:39 UTC] eprayner at gmail dot com
[2009-09-23 23:42 UTC] eprayner at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 22:00:01 2025 UTC |
Description: ------------ When using PDO prepare for mysql, quotes are incorrectly inserted around column names, resulting in errors or unexpected results. This problem would have been _much_ easier to diagonise if there was a way of seeing the actual statement. Something like: $string PDOStatement::executeString()---returns the statement that would have been executed by PDOStatement::execute(). Reproduce code: --------------- //given a mysql connection $pdo //and a database table 'myTable' with columns: id, col1, col2, col3 //with a row: 1, value1, value2, value3. $stmt=$pdo->prepare("SELECT ? FROM myTable WHERE id=?"); $myColumn = 'col1'; $stmt->execute(array($myColumn, 1)); $row=$stmt->fetch(); print_r($row); Expected result: ---------------- I'd expect to see: "value1" displayed, as you'd expect for the statement: "SELECT col1 FROM myTable WHERE id=1" Actual result: -------------- What is displayed is: "col1", as you'd expect for the statement: "SELECT 'col1' FROM myTable WHERE id=1" Other statements result in errors. Example: $stmt=$pdo->prepare("UPDATE myTable SET ?=? WHERE id=?"); $stmt->execute(array($myColumn, $myValue, $myId)); is a syntax error, as is the SQL: UPDATE myTable SET 'col1'=3 WHERE id=1; This problem means that I cant use prepare and execute statements at all.