連接數(shù)據(jù)庫出現(xiàn)警告怎么解決
為什么提示這個警告Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in?D:\phpStudy\WWW\newphp\mysql.php?on line?21
為什么提示這個警告Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in?D:\phpStudy\WWW\newphp\mysql.php?on line?21
2016-10-17
舉報
2016-12-07
$conn=new mysqli('localhost:3306','root','root','test');//連接不行的話,可以換成$conn=mysql_connect('數(shù)據(jù)庫地址','用戶名','密碼');試試。
if(!$conn){
? ? die('連接失?。?.mysql_error);
}
else
? {
? ? echo '連接成功';
? ? ? ? }? ?
}
先試試能否連接數(shù)據(jù)庫,然后在判斷問題。
2016-10-18
$conn=new mysqli('localhost:3306','root','root','test');
if(!$conn){
? ? die('連接失敗:'.mysql_error);
}
else
? {
? ? $sql="select * from user";
? ? $result=$conn->query($sql);
? ? ?while($sr=mysql_fetch_assoc($result)){
? ? ? ? ? echo $sr[0].$sr[1];
? ? ? ? }? ?
}
我就這樣寫,然后就出了上面那個警告,請問這里面那個地方需要修改嗎?幫忙修正一下,謝謝
2016-10-17
應(yīng)該是sql返回的query為空,沒有加判斷直接使用