Why is PDO: prepare used in PHP, and placeholders cannot be used for MySQL table names?

Source: Internet
Author: User
$ Count $ dbh-& amp; gt; prepare (& quot; select * from? Wherescore & amp; lt ;? & Quot;); $ count-& amp; gt; execute (array ($ table, $ score); $ countNum $ count-& amp; gt; rowCount (); returns $ count0 $ count $ dbh-& amp; gt; prepare (& quot; select * from {$ table} whe... $ count = $ dbh-> prepare ("select * from? Where score $ Count-> execute (array ($ table, $ score ));
$ CountNum = $ count-> rowCount ();
Returns $ count = 0.

$ Count = $ dbh-> prepare ("select * from {$ table} where score $ Count-> execute (array ($ score ));
$ CountNum = $ count-> rowCount ();
$ Count = 45

Reply content:

$ Count = $ dbh-> prepare ("select * from? Where score $ Count-> execute (array ($ table, $ score ));
$ CountNum = $ count-> rowCount ();
Returns $ count = 0.

$ Count = $ dbh-> prepare ("select * from {$ table} where score $ Count-> execute (array ($ score ));
$ CountNum = $ count-> rowCount ();
$ Count = 45

The controllable part does not need to be substituted. Do you rely on user input for table names?

Prepare StatementIs to pre-compile the input parameters, not allSQLAll characters can be replaced by placeholders. Only those that meet the parameter conditions can be used for pre-compilation.

It doesn't make much sense to add a table name to prepare, because in case you cannot submit the input, it is completely filled in by yourself, and it should be a constant that cannot be modified, and there is no need for prepare.

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.