mysql_fetch_array() expects parameter 1 to be resource

來源:互聯網
上載者:User
$host = "localhost";
$user = "root";
$password = "123456";

$connection = mysqli_connect($host,$user,$password);
if(!$connection){
exit('串連mysql資料庫失敗!');
}

$dbname = "chuanke";

mysqli_select_db($connection,$dbname);

$sql = "SELECT * FROM `user`";
$result = mysqli_query($connection,$sql);

while($row=mysqli_fetch_array($result))
{
echo $row[`UserName`]."
";
}

?>
這時候提示:Notice: Undefined index
然後我把while($row=mysqli_fetch_array($result))改成while($row=mysql_fetch_array($result))
這時候報錯變成:mysql_fetch_array() expects parameter 1 to be resource,


回複討論(解決方案)


開error_report,
ini_setting("display_errors", 1);
每行代碼都var_dump一下。你差不多就能定位問題了。


加強debug基礎的能力。

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

哎 整了半天是自己粗心 echo $row[`UserName`]."
"; [`UserName`]應該是[’UserName‘] 還是謝謝樓上兩位的協助

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.