Pdostatement::setfetchmode () issue

Source: Internet
Author: User
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.