这是另一个MySql到MySqli转换我遇到了一些困难。
原始代码:
define('DB_DEFAULT_FLAG', MYSQL_ASSOC);
function resource_get($resource = NULL,$flag = DB_DEFAULT_FLAG) {
if(!$resource) $resource = $this->last_resource;
return mysql_fetch_array($resource,$flag);
}
新代码:
define('DB_DEFAULT_FLAG', MYSQL_ASSOC);
function resource_get($resource = NULL, $flag = DB_DEFAULT_FLAG) {
if (!$resource)
$resource = $this -> last_resource;//print_r($resource);
$return = mysqli_fetch_array($resource, $flag) or print("No workie!");
var_dump($return);
return $return;
}
在这种情况下,函数调用失败,返回“No Workie”并且$ return变量中的值为NULL。当我执行print_r($ resource)语句时,数据看起来是正确的。我究竟做错了什么?似乎mysqli_fetch_array语句失败了,但我不知道为什么。有什么指针吗? mysqli_fetch_array或mysql_fetch_array显然应该返回一个数组。
以下是print_r($ resource)返回的示例:
Array ( [0] => Array ( [category] => American Swords [graphics] => 1 [user] => bquinn [i] => 1 [i_categories] => 133 [i_users] => 13 [i_users_modified] => 1 [date_created] => 1266697482 [date_modified] => 1398983308 [active] => 1 [sold] => 0 [filename] => bq203.htm [code] => BQ203 [name] => American Militia-style NCO Sword [cost] => 325.00 [price] => 425.00 [description] => Interesting fluted aluminum handle with gilded brass pommel and crossguard. Blade of lenticular cross-section with no nicks, age-discolored in spots. Showing no maker's markings. Leather scabbard in good condition with brass throat and acorn-finialed chape. Overall 37 5/8", blade 28". [weight] => 5 [height] => 6 [width] => 6 [length] => 48 [keywords] => American sword eagle head sword militia sword american saber
答案 0 :(得分:1)
在新代码上,更改
define('DB_DEFAULT_FLAG', MySQL_ASSOC);
到
define('DB_DEFAULT_FLAG', MySQLi_ASSOC);
答案 1 :(得分:0)
这里的根本问题是我的错误检查。此函数在while循环中运行。通过在此函数中执行print_r()或var_dump(),循环的最后一次迭代抛出了错误,因为它已经耗尽了要处理的数组行。该函数实际上工作正常,直到结束(在我修复了默认标志问题之后)。谢谢你的帮助!