日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php mysql 表字段_php mysql获取表字段名称和字段信息的三种方法

發布時間:2025/3/21 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php mysql 表字段_php mysql获取表字段名称和字段信息的三种方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

php mysql獲取表字段名稱和字段信息的三種方法

先給出本實例中使用的表的信息:

使用desc獲取表字段信息

php代碼如下:

mysql_connect("localhost","root","");

mysql_select_db("test");

$query = "desc student";

$result = mysql_query($query);

while($row=mysql_fetch_assoc($result)){

print_r($row);

}

?>

運行結果:

Array

(

[Field] => student_id

[Type] => int(4)

[Null] => NO

[Key] => PRI

[Default] =>

[Extra] => auto_increment

)

Array

(

[Field] => student_name

[Type] => varchar(50)

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

)

Array

(

[Field] => class_id

[Type] => int(4)

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

)

Array

(

[Field] => total_score

[Type] => int(4)

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

)

使用SHOW FULL FIELDS獲取表字段信息

php代碼如下:

mysql_connect("localhost","root","");

mysql_select_db("test");

$query = "SHOW FULL COLUMNS FROM student";

$result = mysql_query($query);

while($row=mysql_fetch_assoc($result)){

print_r($row);

}

?>

運行結果:

Array

(

[Field] => student_id

[Type] => int(4)

[Collation] =>

[Null] => NO

[Key] => PRI

[Default] =>

[Extra] => auto_increment

[Privileges] => select,insert,update,references

[Comment] =>

)

Array

(

[Field] => student_name

[Type] => varchar(50)

[Collation] => latin1_swedish_ci

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

[Privileges] => select,insert,update,references

[Comment] =>

)

Array

(

[Field] => class_id

[Type] => int(4)

[Collation] =>

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

[Privileges] => select,insert,update,references

[Comment] =>

)

Array

(

[Field] => total_score

[Type] => int(4)

[Collation] =>

[Null] => NO

[Key] =>

[Default] =>

[Extra] =>

[Privileges] => select,insert,update,references

[Comment] =>

)

使用mysql_fetch_field方法獲取表字段信息

php代碼如下:

mysql_connect("localhost","root","");

mysql_select_db("test");

$query = "SELECT * FROM student LIMIT 1";

$result = mysql_query($query);

$fields = mysql_num_fields($result);

for($count=0;$count

{

$field = mysql_fetch_field($result,$count);

print_r($field);

}

?>

運行結果如下:

stdClass Object

(

[name] => student_id

[table] => student

[def] =>

[max_length] => 1

[not_null] => 1

[primary_key] => 1

[multiple_key] => 0

[unique_key] => 0

[numeric] => 1

[blob] => 0

[type] => int

[unsigned] => 0

[zerofill] => 0

)

stdClass Object

(

[name] => student_name

[table] => student

[def] =>

[max_length] => 5

[not_null] => 1

[primary_key] => 0

[multiple_key] => 0

[unique_key] => 0

[numeric] => 0

[blob] => 0

[type] => string

[unsigned] => 0

[zerofill] => 0

)

stdClass Object

(

[name] => class_id

[table] => student

[def] =>

[max_length] => 1

[not_null] => 1

[primary_key] => 0

[multiple_key] => 0

[unique_key] => 0

[numeric] => 1

[blob] => 0

[type] => int

[unsigned] => 0

[zerofill] => 0

)

stdClass Object

(

[name] => total_score

[table] => student

[def] =>

[max_length] => 3

[not_null] => 1

[primary_key] => 0

[multiple_key] => 0

[unique_key] => 0

[numeric] => 1

[blob] => 0

[type] => int

[unsigned] => 0

[zerofill] => 0

)

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

總結

以上是生活随笔為你收集整理的php mysql 表字段_php mysql获取表字段名称和字段信息的三种方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。