开发者

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

When I do:

$q = 'insert into movies values("lion king"); select * from movies;';
$result = $db->query($q);
echo mysqli_num_rows($result);

it says that $result is boolean, not mysq开发者_StackOverflow社区li result. if I check $result like this:

if(!$result) echo 'fail';

it outputs 'fail'.

Is mysql not capable of handling more than 1 query at a time? How do I solve this?


You need to use mysqli::multi_query.


$db->query('insert into movies values("lion king");');
$db->query('select * from movies;');


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


$q = 'insert into movies values("lion king")';
$result = $db->query($q);
$q = 'select * from movies';
$result = $db->query($q);
echo mysqli_num_rows($result);


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜