Mysql错误没有建立连接

时间:2014-05-20 14:42:23

标签: php mysql connection jointable

我有一个联合表查询,但不断收到如下错误:

我还重新创建了数据库,但仍然遇到同样的错误。检查了我与mysql的连接并且工作正常 - 我的联合表查询有什么问题吗?

$select_quote=mysql_query("SELECT authors.name, authors.id, authors.img, authors.slug, quotes.author_id, quotes.title, quotes.id, quotes.meta_keys, quotes.meta_description, quotes.slug, quotes.content
                           from quotes, authors
                           WHERE quotes.author_id = authors.id
                       ORDER BY RAND() LIMIT 1 ");

    while ($row=mysql_fetch_array($select_quote)) {

    $author_id = $row['authors.id'];
    $author_name = $row['authors.name'];
    $author_slug = $row['authors.slug'];

    echo" $author_slug";
    }

这是我的连接

ob_start();
error_reporting(E_ALL); 
ini_set( 'display_errors','1');
$user_name = "root";
$password = "root";
$database = "quotes";
$server = "localhost";
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found) {
 echo "Working";
mysql_close($db_handle);
}
else {
print "Database NOT Found ";
}

这些是我得到的错误

  

警告:mysql_query():无法建立指向服务器的链接   在第6行的/home/user/public_html/index.php

     

警告:mysql_fetch_array()期望参数1是资源,   第11行/home/user/public_html/index.php中给出的布尔值

你能就此提出建议吗?

由于

1 个答案:

答案 0 :(得分:0)

(关闭此问题)

您正在使用mysql_close($db_handle);关闭数据库(如果找到则关闭数据库连接,请将其删除)将其删除或在成功查询后放置。

另外,代替$author_id = $row['authors.id'];执行$author_id = $row['id'];并为其他人执行相同操作。


免责声明:您还应考虑切换到mysqli_或PDO。 mysql_已弃用,将从以后的版本中删除。