为什么mysql事务执行不了?解决办法

WBOY
Release: 2016-06-13 10:17:17
Original
974 people have browsed it

为什么mysql事务执行不了?
php代码片断:  

/*-----数据库连接参数--*/  

$host="localhost";  

$user="root";  

$pwd="xxx";  

$database="luntan";  

/*-----数据库连接-*/  

$db=mysql_connect($host,$user,$pwd);  

$sql="START TRANSACTION;  

  SELECT @A:=MAX(iTopicId) FROM lun_topic;  

  INSERT INTO lun_topic VALUES(@A+1,'主题','内容','作者',NOW(),1);  

  COMMIT;";  

$result=mysql_db_query($database,$sql);//该句执行不了,也不报错  

   

  

表lun_topic  

iTopicId,  

vTitle,  

txtMessage,  

vPostId,  

dPostDateTime,  

iAreaId  

  

---------------------------  

  

注意在MySql中,只有INNODB和BDB类型的表支持事务处理,而缺省的MYISAM类型不支持,可以在创建表的时候指定表类型  

CREATE TABLE t (i INT) TYPE = INNODB;  

  

也可以转换已存在表的表类型  

ALTER TABLE t TYPE=INNODB  

---------------------------  


------解决方案--------------------
你的 $sql 要分作 4 句执行

php 的 mysql 函数,除了定义存储过程外,一次只能执行一条 sql 指令

说的不严密,其实定义存储过程也只是一条指令
------解决方案--------------------
php 的 mysql 函数,除了定义存储过程外,一次只能执行一条 sql 指令

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!