Home > Backend Development > PHP Tutorial > 为什么 INSERT INTO MYSQL 数据库失败?

为什么 INSERT INTO MYSQL 数据库失败?

WBOY
Release: 2016-06-06 16:45:28
Original
1750 people have browsed it

当我用

<span class="x">$sql = "INSERT INTO MSG_TEST(HOUSE_ID,HOUSE_TYPE,PV,UV,CITY_ID,DATELINE) VALUES(13044064,5,6,5,2600,20130227);"; </span>
Copy after login

回复内容:

输出mysql_error();看看。
好像php为了系统安全,不能一次执行多条sql语句。
你换成
<code class="language-sql"><span class="err">$</span><span class="k">sql</span> <span class="o">=</span> <span class="ss">"INSERT INTO MSG_TEST(HOUSE_ID,HOUSE_TYPE,PV,UV,CITY_ID,DATELINE) </span>
<span class="ss">VALUES</span>
<span class="ss">(13044064,5,6,5,2600,20130227),</span>
<span class="ss">(1425578,8,6,5,2500,20130227),</span>
<span class="ss">(18705325,1,3,3,801,20130227)"</span><span class="p">;</span>
<span class="err">看看</span>
</code>
Copy after login
<code class="language-text">回答:
第一,mysql_query函数不允许一次执行多条SQL语句的,还有一个函数好像是 mysql_query_multi (),你查找下函数库或手册;

第二,从你提供的SQL语句看,为了执行性能的高效,写成:
INSERT INTO MSG_TEST(HOUSE_ID,HOUSE_TYPE,PV,UV,CITY_ID,DATELINE) 
VALUES(13044064,5,6,5,2600,20130227),(1425578,8,6,5,2500,20130227)....; 
</code>
Copy after login
手册。
mysql_query
(PHP 4, PHP 5)
mysql_query — 发送一条 MySQL 查询
说明
resource mysql_query ( string $query [, resource $link_identifier ] )
mysql_query() 向与指定的连接标识符关联的服务器中的当前活动数据库发送一条查询。如果没有指定 link_identifier,则使用上一个打开的连接。如果没有打开的连接,本函数会尝试无参数调用 mysql_connect() 函数来建立一个连接并使用之。查询结果会被缓存。
Note:
查询字符串不应以分号结束。

不支持多条语句一起查询。 你确信你写的insert是对的?回去翻翻手册吧。
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