0

In my website I changed this:

$genre_result = mysql_query
(
"       SELECT  g.genre_id, g.genre_name
    FROM    genres as g;"
);
$game_result = mysql_query
(
"       SELECT  g.genre_id, g.game_id, g.game_name
    FROM    games as g;"
);
$genre_array    = array();
$game_array = array();

while ($genre_row = mysql_fetch_row($genre_result))
{
    $genre_index = $genre_row[0] - 1;
    $genre_array[$genre_index] = $genre_row[1];
    $game_array[$genre_index] = array();
    $game_array[$genre_index][] = array();
    $game_array[$genre_index][] = array();
}
while ($game_row = mysql_fetch_row($game_result))
{
    $genre_index = $game_row[0] - 1;
    $game_array[$genre_index][0][] = $game_row[1];
    $game_array[$genre_index][1][] = $game_row[2];
}

to this (I copied the SELECT blocks into two new procedures):

$genre_result = mysql_query
(
    "CALL get_genres();"
);
$game_result = mysql_query
(
    "CALL get_games();"
);
$genre_array    = array();
$game_array = array();

while ($genre_row = mysql_fetch_row($genre_result))
{
    $genre_index = $genre_row[0] - 1;
    $genre_array[$genre_index] = $genre_row[1];
    $game_array[$genre_index] = array();
    $game_array[$genre_index][] = array();
    $game_array[$genre_index][] = array();
}
while ($game_row = mysql_fetch_row($game_result))       // line #61
{
    $genre_index = $game_row[0] - 1;
    $game_array[$genre_index][0][] = $game_row[1];
    $game_array[$genre_index][1][] = $game_row[2];
}

Now I get a PHP error for line #61 (which I have marked in the above code):

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in /home2/isometr1/public_html/keyboard/keyboard.php on line 61

The get_genres() and get_games() procedures work properly in phpmyadmin, returning the proper values. What did I do wrong so that my code doesn't work?

Also, phpmyadmin issues this complaint, though I don't know if it's related:

You are using PHP's deprecated 'mysql' extension, which is not capable of handling multi queries. The execution of some stored routines may fail! Please use the improved 'mysqli' extension to avoid any problems.

[edit 1]

I tried mysql_error() like this:

$genre_result = mysql_query("CALL get_genres();", $con);
echo mysql_errno($con) . ": " . mysql_error($con) . "\n";
$game_result = mysql_query("CALL get_games();", $con);
echo mysql_errno($con) . ": " . mysql_error($con) . "\n";

And got this error:

0: 2014: Commands out of sync; you can't run this command now

Here are my version numbers:

MySQL version 5.1.70-cll
phpMyAdmin version 3.5.8
cpanel version 11
PHP version 5.3.22

[edit 2]

Based on GolezTrol's suggestions I also tried this with no improvement:

// genres & games
$genre_array    = array();
$game_array = array();
$genre_result = mysql_query("CALL get_genres();", $con);
while ($genre_row = mysql_fetch_row($genre_result))
{
    $genre_index = $genre_row[0] - 1;
    $genre_array[$genre_index] = $genre_row[1];
    $game_array[$genre_index] = array();
    $game_array[$genre_index][] = array();
    $game_array[$genre_index][] = array();
}
$game_result = mysql_query("CALL get_games();", $con);
while ($game_row = mysql_fetch_row($game_result))
{
    $genre_index = $game_row[0] - 1;
    $game_array[$genre_index][0][] = $game_row[1];
    $game_array[$genre_index][1][] = $game_row[2];
}
posfan12
  • 2,541
  • 8
  • 35
  • 57
  • 2
    I'd try with mysqli now… – bwoebi Jul 26 '13 at 19:56
  • 1
    What does `mysql_error()` tell you? – andrewsi Jul 26 '13 at 19:57
  • @bwoebi - Unfortunately, I don't know how to upgrade to a newer version, or whether my hosting provider will even let me. andrewsi - Where do I insert this command? – posfan12 Jul 26 '13 at 20:02
  • 1
    The `mysqli` functions are a separate, newer set of functions that might already be available to you. http://php.net/manual/en/mysqlinfo.api.choosing.php – PleaseStand Jul 26 '13 at 20:08
  • I updated my question with new info at the end. – posfan12 Jul 26 '13 at 20:16
  • @posfan12 and php version? – bwoebi Jul 26 '13 at 20:18
  • 1
    php 5.3 supports mysqli. you can use it without problems. Just try it. – bwoebi Jul 26 '13 at 20:23
  • 1
    @bwoebi Even with MySQLi, it would probably yield the same SQL error since the result set is not being freed from the first query before executing the second. Either way, you'd probably need to group the "genres" query and loop together followed by the "games" query and loop. – Wiseguy Jul 26 '13 at 20:29
  • 1
    @GolezTrol See Edit 2. I tried looping one block before starting the other, but I still get the same error. – posfan12 Jul 26 '13 at 21:55
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Jul 26 '13 at 22:20

0 Answers0