Why is MySQL transaction not executing? workaround
Source: Internet
Author: User
Why is MySQL transaction not executing?
PHP Code snippet:
/*-----Database connection Parameters--*/
$host = "localhost";
$user = "root";
$pwd = "xxx";
$database = "Luntan";
/*-----Database connection-*/
$db =mysql_connect ($host, $user, $pwd);
$sql = "START TRANSACTION;
SELECT @a:=max (itopicid) from Lun_topic;
INSERT into Lun_topic VALUES (@a+1, ' theme ', ' content ', ' author ', Now (), 1);
COMMIT; ";
$result =mysql_db_query ($database, $sql);//The sentence can not be executed, nor error
Table Lun_topic
Itopicid,
Vtitle,
Txtmessage,
Vpostid,
Dpostdatetime,
Iareaid
---------------------------
Note that in MySQL, only InnoDB and BDB types of tables support transactions, and the default MyISAM type is not supported, and you can specify the table type when you create the table
CREATE TABLE T (i INT) TYPE = INNODB;
You can also convert table types that already exist in a table
ALTER TABLE T Type=innodb
---------------------------
------Solution--------------------
Your $sql to be executed in 4 sentences.
PHP's MySQL function, in addition to defining stored procedures, can execute only one SQL command at a time
It's not tight, actually. Defining a stored procedure is just an instruction
------Solution--------------------
PHP's MySQL function, in addition to defining stored procedures, can execute only one SQL command at a time
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service