# PDO MySQL - show create table

- Thread: https://externals.io/message/22924
- Original archive: https://news-web.php.net/php.internals/22924
- Started by Ralph Schindler on 2006-04-22T04:56:06+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #22924 — Ralph Schindler — 2006-04-22T04:56:06+00:00

URL: https://externals.io/message/22924#22924

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

---

## #22926 — Wez Furlong — 2006-04-22T14:35:46+00:00

URL: https://externals.io/message/22924#22926 · In reply to: #22924

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 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
