php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57034 Prepare/execute fails
Submitted: 2006-05-23 18:59 UTC Modified: 2006-05-23 20:04 UTC
From: pecl at seven dot net dot nz Assigned:
Status: Not a bug Package: PDO (PECL)
PHP Version: 5.1.2 OS: Ubuntu Dapper / Win XP
Private report: No CVE-ID: None
 [2006-05-23 18:59 UTC] pecl at seven dot net dot nz
Description:
------------
This problem occurs at different times on different OS's/versions.

MySQL version is 5.0.21-Debian_3-log

On Ubuntu Linux (Apache2):
PHP: 5.1.2
PDO: 1.0.3
PDO_MYSQL: 1.0.2 

On Windows XP (cli):
PHP: 5.1.4
PDO: 1.0.3
PDO_MYSQL: 1.0.2 

Reproduce code:
---------------
<?php
$pdo = new PDO('mysql:host=HOST;dbname=DBNAME', 'USERNAME', 'PASSWORD');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$statement = $pdo->prepare("SELECT * FROM ?");
$statement->execute(array ('agent'));
?>

Expected result:
----------------
[Successful execution]

Actual result:
--------------
On Ubuntu 5.1.2, this fails at prepare():

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?' at line 1' in /www/data/realestate/site/test.php:10 Stack trace: #0 /www/data/realestate/site/test.php(10): PDO->prepare('SELECT * FROM ?') #1 {main} thrown in /www/data/realestate/site/test.php on line 10


On Windows 5.1.4, this fails at execute ():

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''agent'' at line 1' in C:\pdo.php:12
Stack trace:
#0 C:\pdo.php(12): PDOStatement->execute(Array)
#1 {main} thrown in C:\pdo.php on line 12


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-23 20:04 UTC] wez@php.net
You can't parameterize table names; your SQL statement is wrong.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Jan 24 23:01:25 2020 UTC