《php和mysql web開發(原書第三版)》中建立CMS系統例子關於mysql的出錯問題?

來源:互聯網
上載者:User

執行index.php檔案時出現的問題,資料庫已經建立。
錯誤提示:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'localhost' (10061) in D:\apmxe\htdocs\28\db_fns.php on line 5

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in D:\apmxe\htdocs\28\index.php on line 8

Fatal error: Call to a member function fetch_assoc() on a non-object in D:\apmxe\htdocs\28\index.php on line 12

開發環境:Apm express

請問這些問題如何解決呢?

補充:index.php串連資料庫部分代碼

$handle = db_connect();  $pages_sql = 'select * from pages order by code';  $pages_result = $handle->query($pages_sql);  echo '
 
  ';        while ($pages = $pages_result->fetch_assoc())   {    $story_sql = "select * from stories                  where page = '{$pages['code']}'                  and published is not null                  order by published desc";       $story_result = $handle->query($story_sql);        if ($story_result->num_rows)     {      $story = $story_result->fetch_assoc();      echo "
  

{$pages['description']}

{$story['headline']}

Read more {$pages['code']} ...

";
/*db_connect函數功能*/function db_connect(){   $handle = new mysqli('localhost', 'content', 'password', 'content');    if (!$handle)   {     return false;   }   return $handle;}

回複內容:

執行index.php檔案時出現的問題,資料庫已經建立。
錯誤提示:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2003): Can't connect to MySQL server on 'localhost' (10061) in D:\apmxe\htdocs\28\db_fns.php on line 5

Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in D:\apmxe\htdocs\28\index.php on line 8

Fatal error: Call to a member function fetch_assoc() on a non-object in D:\apmxe\htdocs\28\index.php on line 12

開發環境:Apm express

請問這些問題如何解決呢?

補充:index.php串連資料庫部分代碼

$handle = db_connect();  $pages_sql = 'select * from pages order by code';  $pages_result = $handle->query($pages_sql);  echo '
      
       ';        while ($pages = $pages_result->fetch_assoc())   {    $story_sql = "select * from stories                  where page = '{$pages['code']}'                  and published is not null                  order by published desc";       $story_result = $handle->query($story_sql);        if ($story_result->num_rows)     {      $story = $story_result->fetch_assoc();      echo "
       

{$pages['description']}

{$story['headline']}

Read more {$pages['code']} ...

";
/*db_connect函數功能*/function db_connect(){   $handle = new mysqli('localhost', 'content', 'password', 'content');    if (!$handle)   {     return false;   }   return $handle;}

mysqli連結的密碼,賬戶都對嗎????

首先確認你構造mysqli對象的時候,所有的參數都是正確的,這四個參數依次是資料庫地址,使用者名稱,密碼,資料庫名。其中資料庫使用者名稱和密碼,你要確認下是否填寫正確了。

然後確認你的資料庫是否啟動了(很多人確實忘了)。在命令列下輸入

telnet localhost 3306

看看是否能夠串連上

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.