How to execute multiple SQL statements at a time in mysql-php Tutorial

Source: Internet
Author: User
How does mysql execute multiple SQL statements at a time? & Lt ;? Php $ SQL & quot; SELECT @ a: idFROMcsdnorderbyidasclimit30, 1; SELECT @ B: idFROMcsdnorderbyidasclimit60, 1; SELECT * fromcsdnwhereid & gt; @ aand mysql?
$ SQL ="
SELECT @ a: = id FROM csdn order by id asc limit 30,1;
SELECT @ B: = id FROM csdn order by id asc limit 60, 1;
SELECT * from csdn where id> @ a and id <@ B;
";

$ Result = mysql_query ($ SQL );
While ($ rs = @ mysql_fetch_array ($ result, MYSQL_ASSOC) {// empty record
Echo"
  • ". $ Rs ['name'];
    }
    ?>

    An empty record is returned.
    Put the content in $ SQL in phpmyadmin and execute it correctly. Therefore, the SQL statement should be correct. it is estimated that there is a problem with the connection method.
    How can I write it to display it? thank you!

    ------ Solution --------------------
    Mysql_query does not support running multiple SQL statements at the same time. You need to separate the marker

    Mysql_query ("SELECT @ a: = id FROM csdn order by id asc limit 30,1 ");
    Mysql_query ("SELECT @ B: = id FROM csdn order by id asc limit 60, 1 ");
    Mysql_query ("SELECT * from csdn where id> @ a and id <@ B ");

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.