note 104363 added to pdo.prepare

From: Date: Fri, 10 Jun 2011 17:09:08 +0000
Subject: note 104363 added to pdo.prepare
Groups: php.notes 
Request: Send a blank email to php-notes+get-180427@lists.php.net to get a copy of this message
Using PDO to do database introspection... <?php // Get a list of tables $tables = array(); $sql = "SHOW TABLES"; $stm = $this->prepare($sql); $result = $stm->execute(); $columnname = 'Tables_in_'. $config['database']; while( $row = $stm->fetchObject() ){ $tables[] = $row->$columnname; } print_r($tables); ?> I just found that it is not possible to prepare "SHOW CREATE TABLE ?" nor "SHOW CREATE TABLE :tablename" however, doing it with string concatenation worked fine: <?php $schemas = array(); foreach($tables as $table) { $sql = 'SHOW CREATE TABLE '. $table; $stm = $this->prepare($sql); $result = $stm->execute(); $columnname = 'Create Table'; while( $row = $stm->fetchObject() ){ $schemas[$table] = $row->$columnname; } } print_r($schemas); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 70.167.213.163 ---- Manual Page -- http://www.php.net/manual/en/pdo.prepare.php Edit -- https://master.php.net/note/edit/104363 Del: integrated -- https://master.php.net/note/delete/104363/integrated Del: useless -- https://master.php.net/note/delete/104363/useless Del: bad code -- https://master.php.net/note/delete/104363/bad+code Del: spam -- https://master.php.net/note/delete/104363/spam Del: non-english -- https://master.php.net/note/delete/104363/non-english Del: in docs -- https://master.php.net/note/delete/104363/in+docs Del: other reasons-- https://master.php.net/note/delete/104363 Reject -- https://master.php.net/note/reject/104363 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#180427) next »