我不明白mysqli和mysql之间的区别,但我在GoDaddy上发现使用:
mysqli_connect不起作用 . mysql_connect确实有效 .
尝试使用以下示例代码来查看是否可以连接到需要至少一个表中的数据的数据库:
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "XXXXXXX.db.XXXXXXXX.hostedresource.com";
$username = "XXXXXXX";
$dbname = "XXXXXXX";
//These variable values need to be changed by you before deploying
$password = "XXXXXXX";
$usertable = "XXXXXXX";
$yourfield = "XXXXXXX";
//Connecting to your database
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
//Fetching from your database table.
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if ($result) {
while($row = mysql_fetch_array($result)) {
$name = $row["$yourfield"];
echo "
some data
";echo "$name
";
}
}
?>