執行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 看看是否能夠串連上 |
|