This problem occurs during the migration from a php5.3 program to php7: 1. I replace all mysql with mysqli2. The mysql result set is correct and the result can be obtained normally, however, after changing to mysqli, you can also get the result. The cause is that after changing to mysqli, The is_resource () method determines... this problem occurs during the migration of php5.3 programs to php7:
1. I replace mysql with mysqli.
2. If the mysql result set is correct, the result can be obtained normally, but the result can also be obtained after mysqli is replaced.
The cause is
After mysqli is changed, the is_resource () method determines that the result set of mysqli is false.
The source code is from a mall program.
static function sqlOfUpdate(&$rs, $data, $InsertIfNoResult = false,$insertData=null,$ignore=false){ $db = kernel::database(); var_dump($rs,is_resource($rs['rs']));exit; if(!is_resource($rs['rs'])){ trigger_error('SqlOfUpdate: '.$rs['sql'].' error ',E_USER_ERROR); } @mysqli_data_seek($rs['rs'],0); $row = mysqli_fetch_assoc($rs['rs']); if($InsertIfNoResult && !$row){ return self::getinsertsql($rs,$data); }
Output result
array(2) {//$rs ["rs"]=> object(mysqli_result)#74 (5) { ["current_field"]=> int(0) ["field_count"]=> int(4) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) } ["sql"]=> string(115) "select * from `sdb_base_cache_expires` where 1 AND `type` = "DB" AND `app` = "base" AND `name` = "BASE_APP_CONTENT""}bool(false)//is_resource($rs['rs'])
After checking the description of php.net, we found that mysql result type exists in the resource type, but mysqli result type does not exist.
Reply content:
This problem occurs during the migration of php5.3 programs to php7:
1. I replace mysql with mysqli.
2. If the mysql result set is correct, the result can be obtained normally, but the result can also be obtained after mysqli is replaced.
The cause is
After mysqli is changed, the is_resource () method determines that the result set of mysqli is false.
The source code is from a mall program.
static function sqlOfUpdate(&$rs, $data, $InsertIfNoResult = false,$insertData=null,$ignore=false){ $db = kernel::database(); var_dump($rs,is_resource($rs['rs']));exit; if(!is_resource($rs['rs'])){ trigger_error('SqlOfUpdate: '.$rs['sql'].' error ',E_USER_ERROR); } @mysqli_data_seek($rs['rs'],0); $row = mysqli_fetch_assoc($rs['rs']); if($InsertIfNoResult && !$row){ return self::getinsertsql($rs,$data); }
Output result
array(2) {//$rs ["rs"]=> object(mysqli_result)#74 (5) { ["current_field"]=> int(0) ["field_count"]=> int(4) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) } ["sql"]=> string(115) "select * from `sdb_base_cache_expires` where 1 AND `type` = "DB" AND `app` = "base" AND `name` = "BASE_APP_CONTENT""}bool(false)//is_resource($rs['rs'])
After checking the description of php.net, we found that mysql result type exists in the resource type, but mysqli result type does not exist.
The result set of mysqli is an object. The use of the is_resource function is certainly false, so there is nothing to worry about.
To determine whether data exists in the result set, you can use the num_rows attribute in the mysqli result set object:
$mysqli_result = $mysqli->query($sql);var_dump($mysqli_result->num_rows);
The reason @ thou95 has already been mentioned. The replacement method can be written like this.
static function sqlOfUpdate(mysqli_result &$rs, $data, $InsertIfNoResult = false,$insertData=null,$ignore=false){...
When defining the rs parameter, addmysqli_resultType.