Check if column exist in Mysql table via php

后端 未结 8 1537
余生分开走
余生分开走 2021-01-04 08:55

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:



        
8条回答
  •  佛祖请我去吃肉
    2021-01-04 09:11

    try

    $result = mysql_query("SHOW COLUMNS FROM `table` LIKE 'fieldname'");
    $exists = (mysql_num_rows($result))?TRUE:FALSE;
    if($exists) {
       // do your stuff
    }
    

    For more :- MySQL, Check if a column exists in a table with SQL

    Note:- mysql_* is deprecated use mysqli or PDO

提交回复
热议问题