The execute () function cannot be found when the PDO continues querying mysql.

Source: Internet
Author: User
The execute () function $ db = newPDO ($ db_config ['dsn '], $ db_config ['username'], $ db_config ['password']); // create a connection $ db-& gt; exec ('setnames '. C ('Db _ charset'); the execute () function cannot be found when mysql is continuously queried by PDO.
$ Db = new PDO ($ db_config ['dsn '], $ db_config ['username'], $ db_config ['password']); // establish a connection
$ Db-> exec ('set names'. C ('Db _ charset '));
$ SQL = "select * from tab limit 1 ";
$ Something = $ db-> prepare ($ SQL );
$ Something-> execute ();
$ Result = $ Something-> fetch ();
Print_r ($ result); // data can be queried here
$ SQL = "select * from tab limit 2 ";
$ Something = $ db-> prepare ($ SQL );
$ Something-> execute (); // An error is reported when the program is executed here.
$ Something-> fetchAll ();
Dump ($ result );
Error message: Fatal error: Call to a member function execute () on a non-object in

------ Solution --------------------
Connection instance between php and pdo database
Http://www.111cn.net/phper/21/pdo_php.htm

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.