How to use pdo prepare-php

Source: Internet
Author: User
Ask Cainiao for instructions on pdo's prepare usage,
Similar to this method, you can query multiple SQL statements at the same time. how can you obtain the result set using prepare?
$dbh = new PDO($dbConnString, $dbInfo['username'], $dbInfo['password']);$query = $dbh->query($queryString);$i = 0;foreach ($query as $query2) {  $queryReturn[$i] = $query2;  $i++;}


Reply to discussion (solution)

I mainly want to use

select SQL_CALC_FOUND_ROWS * from table limit 1,10;select FOUND_ROWS();

One-time query for pagination with parameters

No one else ......

If your SQL command is like #1, sorry!
Select FOUND_ROWS () will not be sent to mysql for execution because it violates the security conventions for executing only one command at a time.

You can write your two commands as a stored procedure.

delimiter //CREATE PROCEDURE `test`()begin  select SQL_CALC_FOUND_ROWS * from table limit 1,10;  select FOUND_ROWS();end;// 
Then execute
$queryString = 'call test();';$query = $dbh->query($queryString);do {  $rows = $query->fetchAll();  print_r($rows);}while($query->nextRowset());

Thanks, xuzuning. if you do not need stored procedures

    begin      select SQL_CALC_FOUND_ROWS * from table limit 1,10;      select FOUND_ROWS();    end;

What about this?

This post was last edited by xuzuning at 09:05:47
If your SQL command is like #1, sorry!
Select FOUND_ROWS () will not be sent to mysql for execution because it violates the security conventions for executing only one command at a time.

Can you write your two commands as the stored procedure SQL code? 1234567 delimiter // CR ......

Can you try it?

Php does not allow the execution of more than one SQL command at a time. it is completely out of the consideration of preventing SQL attacks.

If you use mysqli extension, you can use mysqli_multi_query to execute multiple SQL commands at a time. Of course, you are responsible for security.

Thank you !!!

Can you help me see this problem? Thank you !!!

Http://bbs.csdn.net/topics/390388184

Can you try it?

Php does not allow the execution of more than one SQL command at a time. it is completely out of the consideration of preventing SQL attacks.

If you use mysqli extension, you can use mysqli_multi_query to execute multiple SQL commands at a time. Of course, you are responsible for security.

Can you try it?

Php does not allow the execution of more than one SQL command at a time. it is completely out of the consideration of preventing SQL attacks.

If you use mysqli extension, you can use mysqli_multi_query to execute multiple SQL commands at a time. Of course, you are responsible for security.

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.