如何在PHP中从mySQL数据库中获取一行所有列字段


How to get one row of all column fields from a mySQL database in PHP?

如何在PHP中从mySQL数据库中获取所有列字段中的一行?

我该如何做到这一点,代码方面?如果你真的回应了,你能为一个经验很少的人闭嘴吗?

或者有人能给我密码吗?如果不同意的话,我很抱歉,但我试着自己写,但我缺乏理解和普遍的无能阻碍了我。我甚至试着在这里发布我的代码,但没有帮助,我喜欢在这个项目上至少完成一些工作。我会再次转发我的代码,但我不想重复帖子。

您可以使用mysql_fetch_field从结果中获取列信息,并作为对象返回。

<?php
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$conn) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('database');
$result = mysql_query('select * from table');
if (!$result) {
    die('Query failed: ' . mysql_error());
}
/* get column metadata */
$i = 0;
while ($i < mysql_num_fields($result)) {
    echo "Information for column $i:<br />'n";
    $meta = mysql_fetch_field($result, $i);
    if (!$meta) {
        echo "No information available<br />'n";
    }
    echo "<pre>
blob:         $meta->blob
max_length:   $meta->max_length
multiple_key: $meta->multiple_key
name:         $meta->name
not_null:     $meta->not_null
numeric:      $meta->numeric
primary_key:  $meta->primary_key
table:        $meta->table
type:         $meta->type
unique_key:   $meta->unique_key
unsigned:     $meta->unsigned
zerofill:     $meta->zerofill
</pre>";
    $i++;
}
mysql_free_result($result);
?>

读取货币:

http://php.net/manual/en/function.mysql-fetch-field.php

或者你可以使用:

$result = mysql_query("SELECT names FROM Customers");
$storeArray = Array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $storeArray[] =  $row['names'];  
}
// now $storeArray will have all the names.

阅读更多:

https://stackoverflow.com/a/5229533/3653989

http://php.net/manual/en/function.mysql-fetch-array.php