0

SQL 代码:

SELECT id, album_date AS timestamp, CONCAT((SELECT detail_value
FROM people_db.user_details_tbl WHERE detail_field = 'first_name' AND user_id = pictures_db.albums.owner), ' uploaded pictures!') AS title_html 
FROM pictures_db.albums 
WHERE id IN 
(SELECT DISTINCT(album_id) 
FROM pictures_db.album_pics 
WHERE pic_id IN 
    (SELECT DISTINCT(picture_id) 
    FROM pictures_db.picture_access_tbl 
    WHERE grantee_group_id IN 
        (SELECT group_id 
        FROM people_db.group_membership_tbl
        WHERE member_id = '2'
        )
     )
);

PHP代码:

$albums_sql = mysql_query("SELECT id, album_date AS timestamp, CONCAT((SELECT detail_value 
    FROM people_db.user_details_tbl 
    WHERE detail_field = 'first_name' AND user_id = pictures_db.albums.owner), ' uploaded pictures!') AS title_html 
    FROM pictures_db.albums 
    WHERE id IN (
          SELECT DISTINCT(album_id) 
          FROM pictures_db.album_pics 
          WHERE pic_id IN (
              SELECT DISTINCT(picture_id) 
              FROM pictures_db.picture_access_tbl 
              WHERE grantee_group_id IN (
                  SELECT group_id 
                  FROM people_db.group_membership_tbl 
                  WHERE member_id = '2'
                  )
               )
             )") or die(mysql_error());

当 PHP 运行时,错误是:表 'pictures_db.albums' 不存在

我尝试以同一用户身份执行,重新授予所有权限,甚至刷新权限。在 shell 中工作,而不是在 PHP 中。有任何想法吗?

4

2 回答 2

1

错误信息很清楚:MySQL 看到数据库 pictures_db 但看不到表相册。

这可能是由于权限,但您似乎已经彻底检查过了。

另一个可能的原因是您在 PHP 中使用的连接字符串指向的数据库实例与您在命令行中使用的数据库实例不同。也许连接字符串仍然指向不同的环境,例如 DEV,但您处于 QA 或指向数据库的旧测试版本?

于 2013-01-28T20:08:52.680 回答
0

mysql_select_db()在运行查询之前打电话吗?

mysql_select_db('pictures_db');
于 2013-01-28T20:08:47.710 回答