我曾经使用过这个不好的例子,但是自从我切换后我解决了它。
解决了我的问题。例子 坏:
$currentdj = "SELECT username FROM djsays WHERE current = '1'";
$result = mysql_query($currentdj);
while($dj = mysql_fetch_row($result))
echo $dj;
?>
使用好处:
$mysqli = new mysqli('hostname','user','password','databasename');
if (!$mysqli) {
// connect failure, check connect_error()
echo $mysqli->connect_error();
}
else {
// Call query() to execute your SQL
$result = $mysqli->query("SELECT * FROM some_table");
if ($result) {
// $result is an object of type mysqli_result
// Call fetch_assoc() on $result
while ($row = $result->fetch_assoc())
echo $row['id'];
}
}
?>
答案 0 :(得分:1)
您不能只使用echo打印行,它不会以简单字符串形式返回。
<?php
$currentdj = "SELECT username FROM djsays WHERE current = '1'";
$result = mysql_query($currentdj);
while($dj = mysql_fetch_assoc($result))
{
echo $dj['username'];
}
?>
但是就这一点而言,如果你只是在学习,帮自己一个忙,find a tutorial that shows you how to use PDO,这不是更难,但它是最新的,很多更安全,更多保护您的代码。