note 81899 deleted from function.mysql-fetch-field by danbrown
| From: | danbrown@php.net | Date: | Sat, 20 Jun 2009 02:14:51 +0000 |
| Subject: | note 81899 deleted from function.mysql-fetch-field by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157156@lists.php.net to get a copy of this message | ||
Note Submitter: Christopher Mullins
----
I created the following function to make creating and updating of mysql tables easier. I placed it
here in the hopes that it may be useful for someone else.
<?php
//
// mysql_column_exists(<Table Name>,<Column Name>)
// return type: Boolean
//
function mysql_column_exists($TableName='',$ColumnName='')
{
if(($TableName == '') || ($ColumnName == ''))
{
return False;
}
$QueryStr = sprintf("SHOW COLUMNS FROM %s;",$TableName);
$QueryPtr = mysql_query($QueryStr);
if($QueryPtr === False)
{
return False;
}
while(($QueryRow = mysql_fetch_assoc($QueryPtr)) !== False)
{
if($QueryRow['Field'] == $ColumnName)
{
unset($QueryRow);
mysql_free_result($QueryPtr);
return True;
}
}
return False;
}
?>
- Christopher Mullins