SQL存储过程导致PHP错误

时间:2013-07-26 19:54:36

标签: php mysql

在我的网站上我改变了这个:

$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];
}

到此(我将SELECT块复制到两个新程序中):

$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];
}

现在我收到#61行的PHP错误(我在上面的代码中已标记):

  

警告:mysql_fetch_row()要求参数1为资源,第61行/home2/isometr1/public_html/keyboard/keyboard.php中给出布尔值

get_genres()和get_games()过程在phpmyadmin中正常工作,返回正确的值。我做错了什么,以致我的代码不起作用?

此外,phpmyadmin发出此投诉,但我不知道它是否相关:

  

您正在使用PHP已弃用的“mysql”扩展程序,该扩展程序无法处理多个查询。 执行某些存储的例程可能会失败!请使用改进的'mysqli'扩展名来避免任何问题。

[编辑1]

我试过像这样的mysql_error():

$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";

得到了这个错误:

  

0:2014:命令不同步;你现在不能运行这个命令

以下是我的版本号:

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

[编辑2]

根据GolezTrol的建议,我也尝试了这个但没有改进:

// 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];
}

0 个答案:

没有答案