Is it not possible to run the "show create table __" via PDO? I swear I
was able to do this in the past, and for some reason this is not
working. Am I doing something wrong, is this a bug, or is this planned?
Pasted below is the mysql command and result expected, test code, and
its result.
-ralph
PROOF THE COMMAND WORKS
ralph@localhost ~/development/code/php5.1-200604220230 $ echo "show
create table blog_comments" | mysql -u root --password=xxxxxx test
Table Create Table
blog_comments CREATE TABLE blog_comments
(\n id
int(11) NOT NULL
auto_increment,\n blog_entry_id
int(11) NOT NULL,\n comment
text
NOT NULL,\n comment_datetime
datetime NOT NULL,\n PRIMARY KEY
(id
),\n KEY FK_blog_comments_1
(blog_entry_id
),\n CONSTRAINT
FK_blog_comments_1
FOREIGN KEY (blog_entry_id
) REFERENCES
blog_entries
(id
) ON DELETE CASCADE ON UPDATE CASCADE\n)
ENGINE=InnoDB DEFAULT CHARSET=utf8
THE TEST SCRIPT
ralph@localhost ~/development/code/php5.1-200604220230 $ cat
/home/ralph/development/vhosts/ralphschindler.com/development/test_show.php
<?
$db = new PDO("mysql:dbname=test", "root", "xxxxxx");
echo "\nTEST PREPARED-------\n";
try {
$stmt = $db->prepare("SHOW CREATE TABLE blog_comments");
$stmt->execute();
print_r($stmt); echo "\n";
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
echo "no exceptions\n";
} catch (Exception $e) {
echo $e->getMessage();
echo "exception";
}
echo "\n\nTEST QUERY--------\n";
try {
$thing = $db->query("SHOW CREATE TABLE blog_comments");
print_r($thing); echo "\n";
echo "no exception\n";
} catch (Exception $e) {
echo $e->getMessage();
echo "exception";
}
TEST SCRIPT OUTPUT
ralph@localhost ~/development/code/php5.1-200604220230 $ ./sapi/cli/php
/home/ralph/development/vhosts/ralphschindler.com/development/test_show.php
TEST PREPARED-------
PDOStatement Object
(
[queryString] => SHOW CREATE TABLE blog_comments
)
Array
(
)
no exceptions
TEST QUERY--------
no exception
You need to do this:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
before you call $db->prepare().
hint: if you did this:
$db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
(see http://us2.php.net/manual/en/ref.pdo.php#pdo.error-handling)
you'd get an exception:
'SQLSTATE[HY000]: General error: 2030 This command is not supported in
the prepared statement protocol yet'
--Wez.
Is it not possible to run the "show create table __" via PDO? I swear I
was able to do this in the past, and for some reason this is not
working. Am I doing something wrong, is this a bug, or is this planned?Pasted below is the mysql command and result expected, test code, and
its result.-ralph
PROOF THE COMMAND WORKS
ralph@localhost ~/development/code/php5.1-200604220230 $ echo "show
create table blog_comments" | mysql -u root --password=xxxxxx test
Table Create Table
blog_comments CREATE TABLEblog_comments
(\nid
int(11) NOT NULL
auto_increment,\nblog_entry_id
int(11) NOT NULL,\ncomment
text
NOT NULL,\ncomment_datetime
datetime NOT NULL,\n PRIMARY KEY
(id
),\n KEYFK_blog_comments_1
(blog_entry_id
),\n CONSTRAINT
FK_blog_comments_1
FOREIGN KEY (blog_entry_id
) REFERENCES
blog_entries
(id
) ON DELETE CASCADE ON UPDATE CASCADE\n)
ENGINE=InnoDB DEFAULT CHARSET=utf8THE TEST SCRIPT
ralph@localhost ~/development/code/php5.1-200604220230 $ cat
/home/ralph/development/vhosts/ralphschindler.com/development/test_show.php
<?$db = new PDO("mysql:dbname=test", "root", "xxxxxx");
echo "\nTEST PREPARED-------\n";
try {
$stmt = $db->prepare("SHOW CREATE TABLE blog_comments");
$stmt->execute();
print_r($stmt); echo "\n";
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($result);
echo "no exceptions\n";
} catch (Exception $e) {
echo $e->getMessage();
echo "exception";
}echo "\n\nTEST QUERY--------\n";
try {
$thing = $db->query("SHOW CREATE TABLE blog_comments");
print_r($thing); echo "\n";
echo "no exception\n";
} catch (Exception $e) {
echo $e->getMessage();
echo "exception";
}TEST SCRIPT OUTPUT
ralph@localhost ~/development/code/php5.1-200604220230 $ ./sapi/cli/php
/home/ralph/development/vhosts/ralphschindler.com/development/test_show.phpTEST PREPARED-------
PDOStatement Object
(
[queryString] => SHOW CREATE TABLE blog_comments
)Array
(
)
no exceptionsTEST QUERY--------
no exception