php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43775 PDO can't handle prepared SHOW TABLES statements
Submitted: 2008-01-07 03:52 UTC Modified: 2008-01-07 10:31 UTC
From: adrianamustdie at yahoo dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.5 OS: openSuSE 10.3
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adrianamustdie at yahoo dot com
New email:
PHP Version: OS:

 

 [2008-01-07 03:52 UTC] adrianamustdie at yahoo dot com
Description:
------------
a prepared statement used in a class.

$this->mysql == mysql connection
$database == name of the database

Reproduce code:
---------------
example #1 (work):
$stmt = $this->mysql->prepare("SHOW TABLES FROM ".$database);
$stmt->execute();

example #2 (don't work):
$stmt = $this->mysql->prepare("SHOW TABLES FROM ?");
$stmt->execute(array($database));

Expected result:
----------------
both examples should work!

Actual result:
--------------
error: 42000 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 ''databasename'' at line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-07 10:31 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

That's a limitation inside MySQL. But you can use a query like
  SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = '?'
instead.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 13:01:28 2025 UTC