function fetch($query='', $type = 'BOTH') { $result_type="PDO::FETCH_".$type; $query->setFetchMode($result_type);//这报错,$query是pdo的query结果 $result_arr=$query->fetch(); return $result_arr;}
Pdostatement::setfetchmode (): sqlstate[hy000]: General Error:mode must is an integer
What's the problem? Local Test no problem, put space error
Reply content:
function fetch($query='', $type = 'BOTH') { $result_type="PDO::FETCH_".$type; $query->setFetchMode($result_type);//这报错,$query是pdo的query结果 $result_arr=$query->fetch(); return $result_arr;}
Pdostatement::setfetchmode (): sqlstate[hy000]: General Error:mode must is an integer
What's the problem? Local Test no problem, put space error
No code, no truth.
You have to extract the code and database from your project and make it as simple as possible so that others can reproduce the problem you are experiencing on their computers and then analyze it.
PDO extension in the Windows environment and the Linux environment behavior is not the same, some code in the Windows environment is not error (warning, notice all open also not reported), but in the Linux environment will be error, I met 7 years ago.
Change one line of code:
$query->setFetchMode(constant($result_type));
The Pdostatement::setfetchmode method must pass in the mode parameter of the first int, and you must not pass or pass the int type. As for the local test, it may be that the error output level of the service is not the same as the space.
PDOStatement::setFetchMode ( int $mode );//mode//The fetch mode must be one of the PDO::FETCH_* constants.
A better way to have a picture of the truth:
You understand the meaning of the wrong document, it's a constant for you to fill out a PDO, not a string.