in Education by
I do know that PDO does not support multiple queries getting executed in one statement. I've been Googleing and found few posts talking about PDO_MYSQL and PDO_MYSQLND. PDO_MySQL is a more dangerous application than any other traditional MySQL applications. Traditional MySQL allows only a single SQL query. In PDO_MySQL there is no such limitation, but you risk to be injected with multiple queries. From: Protection against SQL Injection using PDO and Zend Framework (June 2010; by Julian) It seems like PDO_MYSQL and PDO_MYSQLND do provide support for multiple queries, but I am not able to find more information about them. Were these projects discontinued? Is there any way now to run multiple queries using PDO. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
As I know, PDO_MYSQLND replaced PDO_MYSQL in PHP 5.3. Confusing part is that name is still PDO_MYSQL. So now ND is default driver for MySQL+PDO. Overall, to execute multiple queries at once you need: PHP 5.3+ mysqlnd Emulated prepared statements. Make sure PDO::ATTR_EMULATE_PREPARES is set to 1 (default). Alternatively you can avoid using prepared statements and use $pdo->exec directly. Using exec $db = new PDO("mysql:host=localhost;dbname=test", 'root', ''); // works regardless of statements emulation $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); $sql = " DELETE FROM car; INSERT INTO car(name, type) VALUES ('car1', 'coupe'); INSERT INTO car(name, type) VALUES ('car2', 'coupe'); "; $db->exec($sql); Using statements $db = new PDO("mysql:host=localhost;dbname=test", 'root', ''); // works not with the following set to 0. You can comment this line as 1 is default $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1); $sql = " DELETE FROM car; INSERT INTO car(name, type) VALUES ('car1', 'coupe'); INSERT INTO car(name, type) VALUES ('car2', 'coupe'); "; $stmt = $db->prepare($sql); $stmt->execute(); A note: When using emulated prepared statements, make sure you have set proper encoding (that reflects actual data encoding) in DSN (available since 5.3.6). Otherwise there can be a slight possibility for SQL injection if some odd encoding is used.

Related questions

0 votes
    I am looking to get row count to check if same email is already in database or not. i have tried ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    why it's not working.. i want to update my table in database this is my code. for ($i=0; ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I have multiple tables like make, model and year etc and using joins. I would like to search from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I have multiple tables like make, model and year etc and using joins. I would like to search from ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    Symfony version: 3.1.3 Due to development reason suddenly my app giving the following error and I believe ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 8, 2022 in Education by JackTerrance
0 votes
    Hello! Like in title. There is code example. Result is: Nulla eu aliquet sapien. Sed in sagittis ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Hello! Like in title. There is code example. Result is: Nulla eu aliquet sapien. Sed in sagittis ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    Registering members and allowing them to login (updating tables etc) all worked fine up until I made this change recently. ... , make the UserLevel 'Member'? Code for signing up:...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm getting an error with this function: Controller $data['carSubwoofers'] = $this->db->get_where(" ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 24, 2022 in Education by JackTerrance
0 votes
    In Apache Druid, Scan queries do not support pagination. (1)False (2)True...
asked Aug 20, 2021 in Technology by JackTerrance
0 votes
    In Apache Druid , Select queries do not support pagination. (1)True (2)False...
asked Aug 10, 2021 in Technology by JackTerrance
0 votes
    Kafka streams does not support interactive queries to unify the worlds of streams and databases. (1)True (2)False...
asked Jun 16, 2021 in Technology by JackTerrance
0 votes
    As it currently stands, this question is not a good fit for our Q&A format. We expect answers to ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 15, 2022 in Education by JackTerrance
0 votes
    Does Java support multiple level inheritance? (a) True (b) False I had been asked this question during ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
...