note 81899 modified in function.mysql-fetch-field by danbrown

From: Date: Sat, 20 Jun 2009 02:14:19 +0000
Subject: note 81899 modified in function.mysql-fetch-field by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157155@lists.php.net to get a copy of this message
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 --was-- 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. // // 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 http://php.net/manual/en/function.mysql-fetch-field.php

« previous php.notes (#157155) next »