I created mysql tables and there I have put some columns.
Now I want to check that a certain column exists in the database via php.
Like this:
Ok I spent 5 hours on this issue looking through every (sometimes ridiculously convoluted) StackOverflow answer, never finding a working answer, and the answer is so frustratingly simple you will kick yourself (as did I):
php 7
$mysqli = new mysqli($mysql_url, $mysql_user, $mysql_password, $db_name);
$column_name = "my_column";
$table_name = "my_table";
if ($mysqli->query("SELECT $column_name FROM $table_name")){
//my_column exists in my_table
}
else{
//my_column doesn't exist in my_table
}
Databases 101....