gpt4 book ai didi

php - 将函数从MySql转换为MySqli

转载 作者:行者123 更新时间:2023-11-29 00:10:06 25 4
gpt4 key购买 nike

这是另一个MySql到MySql I的转换,我遇到了一些困难。
原始代码:

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

最佳答案

在新代码上,更改
define('DB_DEFAULT_FLAG', MySQL_ASSOC);

define('DB_DEFAULT_FLAG', MySQLi_ASSOC);

关于php - 将函数从MySql转换为MySqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25588774/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com