note 109144 modified in function.mysql-list-fields by danbrown

From: 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.&#13;&#10;&#13;&#10;&#60;?php&#13;&#10;function getColoumn($table) {&#13;&#10;&#9; $result = mysql_query(&#34;SHOW COLUMNS FROM &#34;. $table);&#13;&#10; if (!$result) {&#13;&#10; echo &#39;Could not run query: &#39; . mysql_error();&#13;&#10; }&#13;&#10; $fieldnames=array();&#13;&#10; if (mysql_num_rows($result) &#62; 0) {&#13;&#10; while ($row = mysql_fetch_assoc($result)) {&#13;&#10; $fieldnames[] = $row[&#39;Field&#39;];&#13;&#10; }&#13;&#10; }&#13;&#10;&#13;&#10; return $fieldnames;&#13;&#10;}&#13;&#10;?&#62; --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

« previous php.notes (#188825) next »