Jump to content

Multi-SQL Query


kool_samule

Recommended Posts

Hi Chaps,

 

I'm trying to put together a Nested Set Model (Hierarchical Data), but I have having problems when it comes to deleting/updating the 'nested' table.

 

I'm using this as a guide:

http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

 

But when trying to run a query, such as:

SELECT @myLeft := lft, @myRight := rgt, @myWidth := rgt - lft + 1
FROM nested_category
WHERE name = 'GAME CONSOLES';

DELETE FROM nested_category WHERE lft BETWEEN @myLeft AND @myRight;

UPDATE nested_category SET rgt = rgt - @myWidth WHERE rgt > @myRight;
UPDATE nested_category SET lft = lft - @myWidth WHERE lft > @myRight;

 

I get a MySQL syntax error.

 

This code works fine in something such as Windows Command Prompt, but not in PHP.

 

Is there a special way to run multiple queries in 1 PHP script?

 

Many thanks

Link to comment
Share on other sites

If you use mysqli extension instead there is: http://us2.php.net/manual/en/mysqli.multi-query.php

 

However I'm not sure if the vars defined in the first query will pass to the others.  If not you can probably write a stored procedure:  http://dev.mysql.com/tech-resources/articles/mysql-storedproc.html

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.