我想将作为 MySQL 查询结果返回的列名的所有行存储在字符串数组中。我是 PHP 新手。我已经检索了行,但是如何将列的所有行存储在数组中?
我的意思是如何迭代行的计数器并将列存储在数组中?还是有任何直接的函数/方法调用?请参阅下面的代码及其在数组中存储的可能方式:
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'users';
mysql_select_db($dbname);
$result = mysql_query("SELECT users.email FROM users");
// AND THEN FINALLY STORING IN A STRING ARRAY:
$array = $result;
// OR SOMETHING LIKE:
Store($array, $result);
// OR SOMETHING LIKE:
for(int i = 0; i < $result.Rows.Count; i++)
{
if (null != $row[0])
{
$array[i] = $result[i];
}
}
// OR SOMETHING LIKE:
while($null != result.read())
{
$array.Add($result.Read());
}