PHP 测试服务器出错
PHP error on testing server
我有一些 PHP 代码在我的生产服务器上运行良好,但在我的测试服务器上运行不正常。这是代码:
function callProcedure0(&$connection, $procname, $dofunction)
{
mysqli_multi_query($connection, "CALL " . $procname . "();");
$first_result = 1;
do
{
$query_result = mysqli_store_result($connection);
if ($first_result)
{
$dofunction($query_result);
$first_result = 0;
}
if ($query_result)
{
mysqli_free_result($query_result);
}
$query_result = NULL;
} while(mysqli_next_result($connection));
}
...
function doGenres($in_result)
{
global $genre_array, $game_array, $genre_order_array;
$genre_count = 1;
// foreach is necessary when retrieving values since gaps may appear in the primary key
while ($genre_row = mysqli_fetch_row($in_result)) // line 81 is here!
{
$genre_array[] = $genre_row[0];
$genre_order_array[$genre_row[1] - 1] = $genre_count;
$game_array[] = [[],[]];
$genre_count += 1;
}
}
...
callProcedure0($con, "get_genres_front", doGenres); // line 138 is here!
"get_genres_front" 位指的是我的数据库中的一个存储过程。以下是错误:
Notice: Use of undefined constant doGenres - assumed 'doGenres' in /opt/lampp/htdocs/keyboard/keyboard.php on line 138
同样,使用 Apache 2.2.23、MySQL 5.1.73-cll、PHP 5.4.26 的生产服务器没有问题。出现问题的测试服务器正在运行 Apache 2.4.10、MySQL 5.6.21、PHP 5.5.19。
最近的软件版本有什么变化吗?谢谢。
[编辑]
这不是一个重复的问题。我担心第一个错误。我已经知道如何处理我删除的第二个错误了。
您发布的代码是错误的,您必须将函数名称作为字符串传递,然后使用 call_user_func 来调用此函数。
在您的 callProcedure0 函数中更改
$dofunction($query_result);
至
call_user_func($dofunction, $query_result);
然后像这样用函数名作为字符串调用它
callProcedure0($con, "get_genres_front", "doGenres");
上面的代码也可以用
调用函数
$dofunction($query_result);
在某些 php 版本上,但是传递函数名称的行应该是字符串,否则 PHP 假定它是一个常量。
我有一些 PHP 代码在我的生产服务器上运行良好,但在我的测试服务器上运行不正常。这是代码:
function callProcedure0(&$connection, $procname, $dofunction)
{
mysqli_multi_query($connection, "CALL " . $procname . "();");
$first_result = 1;
do
{
$query_result = mysqli_store_result($connection);
if ($first_result)
{
$dofunction($query_result);
$first_result = 0;
}
if ($query_result)
{
mysqli_free_result($query_result);
}
$query_result = NULL;
} while(mysqli_next_result($connection));
}
...
function doGenres($in_result)
{
global $genre_array, $game_array, $genre_order_array;
$genre_count = 1;
// foreach is necessary when retrieving values since gaps may appear in the primary key
while ($genre_row = mysqli_fetch_row($in_result)) // line 81 is here!
{
$genre_array[] = $genre_row[0];
$genre_order_array[$genre_row[1] - 1] = $genre_count;
$game_array[] = [[],[]];
$genre_count += 1;
}
}
...
callProcedure0($con, "get_genres_front", doGenres); // line 138 is here!
"get_genres_front" 位指的是我的数据库中的一个存储过程。以下是错误:
Notice: Use of undefined constant doGenres - assumed 'doGenres' in /opt/lampp/htdocs/keyboard/keyboard.php on line 138
同样,使用 Apache 2.2.23、MySQL 5.1.73-cll、PHP 5.4.26 的生产服务器没有问题。出现问题的测试服务器正在运行 Apache 2.4.10、MySQL 5.6.21、PHP 5.5.19。
最近的软件版本有什么变化吗?谢谢。
[编辑]
这不是一个重复的问题。我担心第一个错误。我已经知道如何处理我删除的第二个错误了。
您发布的代码是错误的,您必须将函数名称作为字符串传递,然后使用 call_user_func 来调用此函数。
在您的 callProcedure0 函数中更改
$dofunction($query_result);
至
call_user_func($dofunction, $query_result);
然后像这样用函数名作为字符串调用它
callProcedure0($con, "get_genres_front", "doGenres");
上面的代码也可以用
调用函数$dofunction($query_result);
在某些 php 版本上,但是传递函数名称的行应该是字符串,否则 PHP 假定它是一个常量。