Mysql can't perform more than 1 query at a time

前端 未结 5 702
忘了有多久
忘了有多久 2020-12-21 06:42

When I do:

$q = \'insert into movies values(\"lion king\"); select * from movies;\';
$result = $db->query($q);
echo mysqli_num_rows($result);
相关标签:
5条回答
  • 2020-12-21 07:05
    $db->query('insert into movies values("lion king");');
    $db->query('select * from movies;');
    
    0 讨论(0)
  • 2020-12-21 07:10
    $q = 'insert into movies values("lion king")';
    $result = $db->query($q);
    $q = 'select * from movies';
    $result = $db->query($q);
    echo mysqli_num_rows($result);
    
    0 讨论(0)
  • 2020-12-21 07:13

    You can use multi_query which is difficult to use, but in general no, you should only use one query at a time.

    0 讨论(0)
  • 2020-12-21 07:19

    Don't confuse how you write 'queries' in the MySQL command line interface with how you do it with the API.

    The MySQL command just wraps the API with something more shell like.

    Using the API, you can really only do one query at a time. Of course the client side of the API could do something smart and interpret the semi-colons, splitting into multiple queries for you, but that probably just isn't that useful for enough people.

    0 讨论(0)
  • 2020-12-21 07:26

    You need to use mysqli::multi_query.

    0 讨论(0)
提交回复
热议问题