Solution to PDOexecute failure

Source: Internet
Author: User
PDOexecute failed. I saved the session to the mysql database and saved the sessionID to another user table. I want to use the sessionID in the user table to find the corresponding data in the session table. The code is as follows: $ SQL & nbsp; select & nbsp; update_time & nbsp; from & nbsp; admin_session, admin & nbsp PDO execute execution failed
I saved the session to the mysql database and saved the sessionID to another user table. I want to use the sessionID in the user table to find the corresponding data in the session table. The code is as follows:

$ SQL = 'SELECT update_time from admin_session, admin where admin_session.sessid =? ';
$ Stmt = $ pdo-> prepare ($ SQL );
$ Stmt-> execute (array ('admin _ sessid '));
------ Solution --------------------
What is the error message?
------ Solution --------------------
Array ('admin _ sessid ') is not the bound parameter. it must be the admin_sessid string, not the variable value.
------ Solution --------------------

Example #3 use an array containing inserted values to execute a preprocessing statement (placeholder)
/* Execute a preprocessing statement by passing an array of inserted values */
$ Calories = 150;
$ Color = 'red ';
$ Something = $ dbh-> prepare ('select name, color, calories
FROM fruit
WHERE calories <? AND color =? ');
$ Something-> execute (array ($ calories, $ color ));
?>


------ Solution --------------------
Execute (array ('admin _ sessid '). The execution result is false.
This indicates an error. because it is not a php error, it will not be automatically prompted.
You can print the result of errorInfo to view

------ Solution --------------------
Find a data from two tables?
Join two tables for query!
------ Solution --------------------
It is bound with a value, not a field name.
At least write like this
$ SQL = 'SELECT update_time from admin_session, admin where admin_session.sessid = admin. sessid and admin. sessid =? ';

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.