Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4611186
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:14:02+00:00 2026-05-22T01:14:02+00:00

As in PHP multiple queries are not supported using mysql_query(), how could I convert

  • 0

As in PHP multiple queries are not supported using mysql_query(), how could I convert the following code to become a unique query ?

I precise that I can’t change my database to MySQLi or anything else.

SELECT @myLeft := lft FROM hierarchie WHERE id = ".$father_id.";
UPDATE hierarchie SET rgt = rgt+2 WHERE rgt > @myLeft;
UPDATE hierarchie SET lft = lft+2 WHERE lft > @myLeft;
INSERT INTO hierarchie VALUES(".$cat.", ".$id.", '".$fullindi."', @myLeft+1, @myLeft+2);

Any help will be greatly appreciate.

Best regards.

UPDATE :

Answering to my own question, I found the link : http://www.dev-explorer.com/articles/multiple-mysql-queries where the author expalins how to do it.

For me, and following his explanations, the code becomes :

$sql = "
SELECT @myLeft := lft FROM hierarchie WHERE id = ".$father_id.";
UPDATE hierarchie SET rgt = rgt + 2 WHERE rgt > @myLeft;
UPDATE hierarchie SET lft = lft + 2 WHERE lft > @myLeft;
INSERT INTO hierarchie VALUES(".$cat.", ".$id.", '".$fullindi."', @myLeft + 1, @myLeft + 2);
";
$queries = preg_split("/;+(?=([^'|^\\\']*['|\\\'][^'|^\\\']*['|\\\'])*[^'|^\\\']*[^'|^\\\']$)/", $sql);
foreach ($queries as $query){
   if (strlen(trim($query)) > 0) mysql_query($query);
} 

I’ve tested and it works well.

We can consider the problem is resolved, except if one of you has a better solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T01:14:03+00:00Added an answer on May 22, 2026 at 1:14 am

    The solution is to use transactions so you can execute those queries separately but they will be considered as one.

    START TRANSACTION;
    SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
    UPDATE table2 SET summary=@A WHERE type=1;
    COMMIT;
    

    So, for instance, the example above will require 4 mysql_query() commands but mysql will execute the whole thing as one query;

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to deploy my php/html/css/etc code to multiple servers and i am looking
Are there any more generic tools that can compile or basically merge multiple PHP
I am wondering how I can break up my index.php homepage to multiple php
Situation: A PHP application with multiple installable modules creates a new table in database
I need to test my PHP applications with multiple versions of PHP 5.x, such
I am looking for a way to maintain PHP sessions across multiple domains on
On one Linux Server running Apache and PHP 5, we have multiple Virtual Hosts
PHP, as we all know is very loosely typed. The language does not require
In PHP, I want to insert into a database using data contained in a
I am trying to add or connect multiple sql queries dynamically. I am creating

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.