MySQL查询结果在PHP变量
问题描述:
有什么方法可以将mysql结果存储在php变量中?谢谢
Is there any way to store mysql result in php variable? thanks
$query = "SELECT username,userid FROM user WHERE username = 'admin' ";
$result=$conn->query($query);
然后我要从查询中打印选定的用户ID.
then I want to print selected userid from query.
答
当然有.检出mysql_query
和mysql_fetch_row
(如果使用MySQL).
PHP手册中的示例:>
Of course there is. Check out mysql_query
, and mysql_fetch_row
if you use MySQL.
Example from PHP manual:
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 42
echo $row[1]; // the email value
?>