note 109144 modified in function.mysql-list-fields by danbrown
| From: | danbrown@php.net | Date: | Tue, 26 Jun 2012 13:50:32 +0000 |
| Subject: | note 109144 modified in function.mysql-list-fields by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188825@lists.php.net to get a copy of this message | ||
Below script is used to get all coloumn indormation of an table.When we are working custome ORM then
we need to match the coloumn name with array
keys. <?php function getColoumn($table)
{ 	 $result = mysql_query("SHOW COLUMNS FROM ".
$table); if (!$result) { echo 'Could not run
query: ' . mysql_error(); }
$fieldnames=array(); if (mysql_num_rows($result) > 0)
{ while ($row = mysql_fetch_assoc($result)) {
$fieldnames[] = $row['Field']; }
} return
$fieldnames; } ?>
--was--
Below script is used to get all coloumn indormation of an table.When we are working custome ORM then
we need to match the coloumn name with array keys.
function getColoumn($table) {
$result = mysql_query("SHOW COLUMNS FROM ". $table);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
}
$fieldnames=array();
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$fieldnames[] = $row['Field'];
}
}
return $fieldnames;
}
more
<a herf="http://phpflow.com">phpflow.com</a>
http://php.net/manual/en/function.mysql-list-fields.php