Check if column exist in Mysql table via php

后端 未结 8 1443
余生分开走
余生分开走 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:22
    If your database is MySQL then, you can use mysql_field_name() and mysql_fetch_field() function in php.
    
    $res = mysql_query('select * from customer', $link);
    
    echo mysql_field_name($res, 0); // print cust_id
    echo mysql_field_name($res, 1); // print cust_name 
    echo mysql_field_name($res, 2); // print cust_age
    
    0 讨论(0)
  • 2021-01-04 09:37

    Run this query in php and check if number of rows > 0 :- DESC tablename '%columns_name%'

    0 讨论(0)
提交回复
热议问题