Home > Backend Development > PHP Tutorial > mysql如何一次执行多条SQL语句

mysql如何一次执行多条SQL语句

WBOY
Release: 2016-06-13 10:22:37
Original
1111 people have browsed it

mysql怎么一次执行多条SQL语句?
$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";

$result=mysql_query($sql);
while($rs = @mysql_fetch_array($result,MYSQL_ASSOC)){//空记录
echo "

  • ".$rs['name'];
    }
    ?>

    上面返回空记录。
    单独将$sql里面的内容放在phpmyadmin中执行正确,所以SQL语句应该是正确,估计连接方式那城出了问题
    请问如何写才能显示出来,谢谢!

    ------解决方案--------------------
    mysql_query不支持同时运行多条SQL。你要以;号拆开分别执行

    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
  • Related labels:
    source:php.cn
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Popular Tutorials
    More>
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template