1

Here is query

 BEGIN; 
 SELECT NumberRenamed, ... FROM 2_1_paidused WHERE CreditAccount = ? AND ...; 
 SELECT NumberRenamed, ... FROM 2_1_paidused WHERE DebitAccount = ? AND  ...; 
 COMMIT;`

(... is long list with columns and conditions).

and get SQLSTATE[HY000]: General error.

Removed BEGIN; and COMMIT; and all works as expected without errors.

From my knowledge if more than one SELECT, then need to use BEGIN; and COMMIT; But appears that I am wrong. So, does it mean that it is allowed to use more than one SELECT without BEGIN; and COMMIT;? Or my query is incorrect?

Andris
  • 1,434
  • 1
  • 19
  • 34

1 Answers1

2

Those are four SQL statements. You don't share any PHP code but the way you display the queries suggest that you launch them at once into a single database call. Apparently, running multiple queries in PDO is quite tricky—no idea if you got it right.

In any case, your transaction code is redundant:

  • PDO has builtin functions to start and commit transactions. There's no need to run commands manually.
  • You don't write into the database, thus transactions don't have any purpose anyway.

I'm pretty sure you just need to run your two SELECT queries separately.


Edit: perhaps you're confused with BEGIN ... END. That's an entirely different feature. In MySQL, you can only use it in the body of stored routines.

Community
  • 1
  • 1
Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Yes, it is a single database call. Single, because I supposed, that single call would use less resources. Thanks for explanation – Andris Apr 30 '14 at 16:03
  • If you remove the transaction code and follow the advice in the linked question to issue a 2-query call, you shouldn't get an error. But I'm not sure there's a way to *fetch* the results (I've never tried). – Álvaro González Apr 30 '14 at 16:08