如何在一个mysql_query中执行多个SQL语句? [英] How do you do multiple SQL statements in one mysql_query?

查看:244
本文介绍了如何在一个mysql_query中执行多个SQL语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我想做UPDATE table SET name = 'bob'UPDATE table SET age = 55 WHERE name = 'jim',如何在同一个mysql_query()中做它们?

Say I wanted to do UPDATE table SET name = 'bob' and UPDATE table SET age = 55 WHERE name = 'jim' how do I do them in the same mysql_query()?

编辑:由于这个问题有很多见解,我想指出,从PHP 5.5开始,mysql_query和其他mysql_*函数现在已被弃用,不应删除使用.

Since this question has a fair amount of views I'd like to point out that as of PHP 5.5 mysql_query and other mysql_* functions are now deprecated and shouldn't be used.

推荐答案

我从未尝试过,但是我认为您可以使用

I've never tried this, but I think you can use mysqli::multi_query. One of the good things about mysql_query rejecting multiple statements is that it immediately rules out some of the more common SQL injection attacks, such as adding '; DELETE FROM ... # to a statement. You might therefore want to be careful with multiple statements.

这篇关于如何在一个mysql_query中执行多个SQL语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆