RE: [PHP] output the schema

From: Date: Fri, 03 Aug 2007 12:43:00 +0000
Subject: RE: [PHP] output the schema
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-260121@lists.php.net to get a copy of this message
<assuming name="database" value="MySQL" NOT SPECIFIED> You would probably want to use the combination of the MySQL query "SHOW COLUMNS FROM <tablename>" and the PHP function mysql_field_type(). An example would be: <? //Establish connection and select database here $sql = "SHOW COLUMNS FROM myTable"; $result = @mysql_query($sql, <connection>) or die(); //Dummy variable for incrementing current field $count = 0; while($row = mysql_fetch_row($result) { echo "Field: ".$row[0]." Type: ".mysql_field_type($result,$count); $count++; } ?> Further information and example usage of mysql_field_type() can be found at: http://us3.php.net/mysql_field_type Additionally, that site's sidebar lists other useful MySQL functions in PHP. </assuming> -- N/A -----Original Message----- From: Hulf [mailto:ross@blue-fly.co.uk] Sent: Friday, August 03, 2007 6:09 AM To: php-general@lists.php.net Subject: [PHP] output the schema Hi, I reword my last post. I want to take the result and generate the field info to the screen e.g id, int(10) name, varchar(30) age, varchar(30). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#260121) next »