mysql_fetch_array() expects parameter 1 to be resource, string given.
谢谢你的任何建议.
class DBConn /*extends Config*/ {
public function dbConnection(){
$db_host = 'localhost';
$db_login = 'root';
$db_password = '';
$db_name = "database";
$conn = mysql_connect($db_host, $db_login, $db_password);
$db = mysql_select_db($db_name);
}
}
class DBQueries extends DBConn {
function displayUsers(){
$this->dbConnection();
$query = "SELECT * FROM users";
$result = mysql_query($query);
while ($row = mysql_fetch_array($query)) {
echo $row['password'];
}
}
}
解决方法:
当你需要传入$result这是你的db结果对象时,你传入$query这是你的sql字符串.
class DBQueries extends DBConn {
function displayUsers(){
$this->dbConnection();
$query = "SELECT * FROM users";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo $row['password'];
}
}
}
标签:php,mysql,oop
来源: https://codeday.me/bug/20190926/1819916.html