Check if column exist in Mysql table via php

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

    This is simple but it works for me:

    1) Select all from the table you want.

    $qry = "SELECT * FROM table";
    

    2) Bring the result and verify if the field exists.

    if( $result = $mysqli->query($qry)  &&  isset($result['field_you_want']) ){
        //Exists
    }else{
        //Doesn't exists
    }
    

提交回复
热议问题