如何从 PHP 中的 mySQL 数据库中获取所有列字段的一行?
How to get one row of all column fields from a mySQL database in PHP?
如何从 PHP 中的 mySQL 数据库中获取所有列字段的特定行?
我该怎么做,代码明智?如果你真的回应了,你能为一个经验很少的人把它简化一下吗?
或者有人可以给我代码吗?对不起,如果有人不赞成,但我试着自己写,但我缺乏理解和普遍的无能挫败了我。我什至尝试过在这里发布我的代码,但没有帮助,我希望至少在这个项目上完成一些工作。我会再次重新发布我的代码,但我不想重复发布。
您可以使用 mysql_fetch_field
从结果中获取列信息,并 return 作为对象。
<?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);
?>
阅读货币:
或者您可以使用:
$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.
阅读更多内容:
如何从 PHP 中的 mySQL 数据库中获取所有列字段的特定行?
我该怎么做,代码明智?如果你真的回应了,你能为一个经验很少的人把它简化一下吗?
或者有人可以给我代码吗?对不起,如果有人不赞成,但我试着自己写,但我缺乏理解和普遍的无能挫败了我。我什至尝试过在这里发布我的代码,但没有帮助,我希望至少在这个项目上完成一些工作。我会再次重新发布我的代码,但我不想重复发布。
您可以使用 mysql_fetch_field
从结果中获取列信息,并 return 作为对象。
<?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);
?>
阅读货币:
或者您可以使用:
$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.
阅读更多内容: