Check if column exist in Mysql table via php

后端 未结 8 1536
余生分开走
余生分开走 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
    

提交回复
热议问题