How do I find if a column exists or not using PHP + mysqli database.
I've been trying these and also comment part..but nothing seems to be working.
$column1="address";
$chkcol="SELECT * FROM `table_name` LIMIT 1";
/* $chktable="SELECT * FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = `db_name` AND TABLE_NAME = `table_name` AND COLUMN_NAME = `$col_name`";*/
$mycol = mysqli_fetch_array($chkcol);
/* echo $val=mysqli_query($conn,$chktable);
echo $val; */
if(isset($mycol['$column1']))
{
$message="Adress column already exists.";
echo $message;
}
else
{
echo "Column doesn't exist";
}
If there's any shortcode or simple code to make it work. Then let me know. This isn't MySQL, it's MySQLi(Procedural), since the earlier answers I found were MySQL (Obj Oriented) does't work.