爲什麼我無法連接數據庫?我已經下面的代碼一個文件「connect.inc.php」:無法連接數據庫
<?php
$conn_error='Could not connect.';
$mysql_host='localhost';
$mysql_user='root';
$mysql_pass='';
$mysql_db='a_database';
if([email protected]_connect($mysql_host,$mysql_user,$mysql_pass,$mysql_db)
|| [email protected]_select_db(mysqli_connect($mysql_host,$mysql_user
,$mysql_pass,$mysql_db), $mysql_db))
{
die($conn_error);
}
?>
,另一種是具有下面的代碼索引頁:
<?php
require 'connect.inc.php';
echo 'Ok';
?>
這是錯誤:
Warning: require(connect.inc.php): failed to open stream: No such
file or directory in C:\xampp\htdocs\ConnectingToServerAndDatabase
\index.php on line 2
Fatal error: require(): Failed opening required 'connect.inc
php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\
ConnectingToServerAndDatabase\index.php on line 2
@選項OP使用'mysqli' ... – arkascha
問題是包含該php文件,而不是連接到數據庫。 – arkascha
我只使用mysqli_。 –