How to obtain the SQL statement after prepare

Source: Internet
Author: User
Tags sql using
{Code...} Then {code ...}
$ Db = new PDO (); $… = $ db-> prepare ('SQL'); // you can obtain the execution SQL using a method similar to getSql =

Then

$ Db = new PDO (); $… = $ db-> prepare ('select * from 'table' where p1 =: p1 limit: limit '); $ something-> bindValue (': p1', $ var_p1, PDO: PARAM_INT); $ something-> bindValue (': limit ', $ var_limit, PDO: PARAM_INT ); # ^ This is correct. $……> execute (array (intval ($ var_p1), intval ($ var_limit); # ^ indicates a gross error ?, In execute, can it be converted to int? Must I specify a binding type?

Reply content:
$ Db = new PDO (); $… = $ db-> prepare ('SQL'); // you can obtain the execution SQL using a method similar to getSql =

Then

$ Db = new PDO (); $… = $ db-> prepare ('select * from 'table' where p1 =: p1 limit: limit '); $ something-> bindValue (': p1', $ var_p1, PDO: PARAM_INT); $ something-> bindValue (': limit ', $ var_limit, PDO: PARAM_INT ); # ^ This is correct. $……> execute (array (intval ($ var_p1), intval ($ var_limit); # ^ indicates a gross error ?, In execute, can it be converted to int? Must I specify a binding type?

Not the type of problem, take a closer look at the document: http://cn2.php.net/manual/zh/pdostatement.execute.php

You must use the question mark placeholder when calling the prepare method like execute. Since the "colon parameter name" method is used, the array passed during execute must also use the colon parameter name as the array subscript.

In addition, do you want to obtain the SQL statement that replaces the placeholder with the actual parameter value? PDO cannot be implemented because prepared statement is essentially a temporary stored procedure.

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.