0

I have a two MySQL queries I'd like to combine, it works when I enter them directly to phpmyadmin. I get those queries like this:

$sqlCombine = $sqlStart.";".$sqlStartBefore;
$conn->query($sqlCombine);
echo $sqlCombine;

echo gives the following:

UPDATE rn_slots_availability SET slot_avail_noclean = slot_avail_noclean -1 WHERE hotel_id = '5' AND room_type_id = '6' AND slot_date = '2014-09-05';UPDATE rn_slots_availability SET slot_avail_clean = slot_avail_clean -1 WHERE hotel_id = '5' AND room_type_id = '6' AND slot_date = '2014-09-06'

copy/paste to phpmyadmin works like a charm, executing directly does not, gives the following error:

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE rn_slots_availability SET slot_avail_clean = slot_avail_clean -1 WHERE ho' at line 1

That is the second query, but I don't see why?

7
  • 1
    You can't execute multiple queries by separating them with ; in PHP. We also don't know what interface you use for MySQL interaction, so no one can suggest a workaround or proper approach. Commented Sep 5, 2014 at 10:13
  • 1
    @N.B.: To be a little more precise, you can not with the mysql extension – mysqli however has mysqli::multi_query. Commented Sep 5, 2014 at 10:15
  • @CBroe - I know that. Please read the rest of my comment, I'm fully aware if multiquery, but issuing queries in such a way is not good in my opinion. Hence I would suggest a different, better approach, had I known the interface used by the OP. Commented Sep 5, 2014 at 10:18
  • @CBroe - are we really going to debate like 2 monkeys over a trivial matter? I know about multiquery, you jumped in and "told" me about it - the problem at hand is not measuring our e-peens, but helping someone solve the problem. Depending if mysql, mysqli or PDO are used, there are solutions in form of multiquery, or a different approach. If you can agree with me on that, then we can spend our time sharing actual useful advice. Commented Sep 5, 2014 at 10:53
  • I work with mysqli, how would I create such a multiquery? Could be more than two though. Commented Sep 5, 2014 at 12:51

1 Answer 1

1

Your current configuration doesn't support multiquery for some reason. If you don't care about the way you are executing them, just do the queries one at a time like this:

$conn->query($sqlStart);
$conn->query($sqlStartBefore);

Error should be gone.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, I'll do it like that then. Which config does not allow that, PHP or MySQL?
It's from PHP. As you said, it's working from MySQL's cmd. There are solutions for making it possible but, for this, more details about your script are needed. Anyway, I don't think that executing the queries one at a time is a problem, so you can leave it like this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.