继续获取相同的错误消息 (警告:mysql_connect()[function.mysql-connect]:无法通过/ home / content / 00/7882800 / html中的套接字'/var/lib/mysql/mysql.sock'(2)连接到本地MySQL服务器第27行/Connections/dueslogin.php 无法连接到数据库!请稍后再试。)
<?php
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "TarHeelsDues.db.7882800.hostedresource.com";
$username = "TarHeelsDues";
$dbname = "TarHeelsDues";
//These variable values need to be changed by you before deploying
$password = "************";
$usertable = "DuesLogin";
$yourfield = "your_field";
//Connecting to your database
mysql_connect($hostname, $dbname, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($TarHeelsDues);
//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 "Name: $name<br>";
}
}
?>
答案 0 :(得分:3)
将mysql_connect行更改为
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
答案 1 :(得分:1)
那里有一点错误,你必须在mysql_connect中使用$ username而不是$ dbname。
mysql_connect($hostname, $username , $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($TarHeelsDues);
答案 2 :(得分:1)
正确的语法应该是这样的: -
mysql_connect($ hostname,$ username,$ password)或死(&#34;无法与服务器连接&#34;); mysql_select_db($ TarHeelsDues)或死(&#39;无法连接数据库!&#39;);