php - Check if field of table has NOT NULL property set -


i want check whether field in table has been defined not null.

so lets have following code create sql query:

$sql = "create table `testdb`.`test` (`a` int null, `b` int not null default \'2\');"; 

now want write code in php can query table whether or not field b defined not null or not. suppose more general question here how query table properties of fields.

here go:

$table = 'my_table'; $result = mysql_query('describe `' . $table . '`');  while($item = mysql_fetch_assoc()){     print_r($item); // output properties of table } 

in $item you'll have property called null either no or yes.


Comments