好像我的PHP
尝试使用我未提供的用户名登录MySQL
数据库。
我得到的错误是:
Warning: mysql_query(): Access denied for user 'radiocaf'@'localhost' (using password: NO) in /home/radiocaf/public_html/layout.php on line 16
Warning: mysql_query(): A link to the server could not be established in /home/radiocaf/public_html/layout.php on line 16
我肯定在提供密码,而且我没有在我的连接文件中使用“radiocaf”作为用户名,所以经过3个小时的盯着后,我仍然无法解决我出错的地方。
这是我的代码:
PSL-config.php中:
define("HOST", "localhost");
define("USER", "carl");
define("PASSWORD", "xxxxxxxxx");
define("DATABASE", "wlist");
db_connect.php
include_once 'psl-config.php'; // As functions.php is not included
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
然后最后,我收到错误的主页面(我已经删除了PHP之间的HTML:
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include Connection PHP and connect
include_once('includes/db_connect.php');
//Check Connection
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
};
if (!$query = mysql_query("SELECT * FROM (
(SELECT * FROM users)
UNION ALL
(SELECT * FROM members)
) results
ORDER BY Name DESC")){
die("Error: " . mysqli_error($mysqli));
}
if (!$result = $mysqli->query($query)){
printf("Error: %s\n", $mysqli->error);
}
<HTML>
echo "<table border='0' cellpadding='0' cellspacing='0'>";
$x=0;
while($row = mysql_fetch_assoc($result)):
if ($x<10){
echo "<tr><td width='400' height='30' background='../images/green1.jpg'>".$row["Name"]."</td></tr>";
}
$x++;
if ($x == 10){
echo "<tr><td width='400' height'30' background='../images/green1.jpg'>More...</td></tr>";
break;
}
endwhile;
echo "</table>";
<HTML>
$mysqli->close();
周围的HTML
只是页面的布局,基本上只是一个photoshop布局,切片并导出到网页。
我对PHP
相当新,所以我希望这个问题尽可能的解释。
非常感谢你们,我很抱歉你们有些人认为这个问题很糟糕。不幸的是,我不会看到“拼写错误”,因为我真的不知道我试图同时使用mysql
和mysqli
并且他们无法相互“沟通”。我发现的另一个问题是Dreamweaver将 layout.php 的代码上传为
以下是我更改的旧代码行(在 layout.php 中):
if (!$query = mysql_query("SELECT * FROM (
while($row = mysql_fetch_assoc($result)):
更改为:
if (!$query = "SELECT * FROM (
while($row = mysqli_fetch_assoc($result)):
这就是全部,但我非常感激!再次感谢大家!
答案 0 :(得分:6)
您的MySQL
和MySQLi
存在冲突。 MySQL和MySQLi是两种不同的方法
警告是:
Warning: mysql_query(): .....
但是您要将数据库与mysqli
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);.
php.net
中的警告:
MySQL 扩展名在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应使用
MySQLi
或PDO_MySQL
扩展名。
答案 1 :(得分:0)
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
//Include Connection PHP and connect
//include_once('includes/db_connect.php');
$con=mysqli_connect(HOST, USER, PASSWORD, DATABASE);
//Check Connection
if ($mysqli->connect_error) {
die('Connection failed: ' . $mysqli->connect_error);
};
if (!$query = mysqli_query($con,"SELECT * FROM (
(SELECT * FROM users)
UNION ALL
(SELECT * FROM members)
) results
ORDER BY Name DESC")){
die("Error: " . mysqli_error($mysqli));
}
if (!$result = $mysqli->query($query)){
printf("Error: %s\n", $mysqli->error);
}
?>
<HTML>
<body>
<?php
echo "<table border='0' cellpadding='0' cellspacing='0'>";
$x=0;
while($row = mysqli_fetch_assoc($result)):
if ($x<10){
echo "<tr><td width='400' height='30' background='../images/green1.jpg'>".$row["Name"]."</td></tr>";
}
$x++;
if ($x == 10){
echo "<tr><td width='400' height'30' background='../images/green1.jpg'>More...</td></tr>";
break;
}
endwhile;
echo "</table>";
$mysqli->close();
?>
</body>
<HTML>