-1

I'm trying to use some simple code that's used elsewhere to access content from a MySQL database.

Code...

    $rec_sessions_array = array();
    $sql = "SELECT member_id FROM " . TABLE_PREFIX . "rec_sessions WHERE course_id = $course_id";
    $result = mysql_query($sql, $db);
    if($result && mysql_num_rows($result) > 0){
        while ($row = mysql_fetch_assoc($result)) {
            $rec_sessions_array[] = $row['member_id'];
        }
    }

I keep getting "Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in [path to my script] on line 367". Line 367 is the $result = mysql_query($sql, $db); from above.

When I echo $sql it's correct. When I run that query directly via PHP MyAdmin, it works fine.

Any ideas?

Also, before you say anything about getting away from mysql functions, I know. I'm just trying to augment something that already exists.

gtilflm
  • 1,389
  • 1
  • 21
  • 51

1 Answers1

0

Utilizing global $db; higher in the code seems to have fixed this.

Credit goes to "Dagon" in the comments.

gtilflm
  • 1,389
  • 1
  • 21
  • 51
  • global is not generally a good idea - i guess the above code is in a function? you should parse $db as an argument –  Sep 19 '15 at 01:31