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