0

SQL Code:

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 Code:

$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());

When the PHP is run, the error is: Table 'pictures_db.albums' doesn't exist

I tried executing as the same user, regranted all permissions, and even flushed privileges. Works in shell, not in PHP. Any ideas?

2
  • My first thought is that maybe you shouldn't have pictures_db in the front. Just refer to the table name, since you should already be connected to a specific database. Also, would you consider formatting the code on multiple lines or something? Commented Jan 28, 2013 at 20:07
  • B.T.W. is member_id a VARCHAR? And if this is new code use MYSQLI instead of MYSQL. Commented Jan 28, 2013 at 20:13

2 Answers 2

1

The error message is quite clear: MySQL sees the database pictures_db but not the table albums.

That could be due to permissions, but you seem to have checked that thoroughly.

Another possible reason is that the connection string you're using in PHP points to a different database instance than the one you're using at the command line. Perhaps the connection string still points to a different environment, such as DEV but you're in QA or points to an old test version of the database?

Sign up to request clarification or add additional context in comments.

2 Comments

Right on! Wrong instance... I am coding too late to catch that myself. Thanks
@user1955162 is your question solved? Please accept the answer.
0

Do you call mysql_select_db() before running the query?

mysql_select_db('pictures_db');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.