php - PDO 事务代码警告与 mysqli

标签 php mysql database mysqli pdo

所以我的问题是我应该使用 PDO 还是 mysqli。我担心使用 PDO,因为来自 php PDO page 的以下警告.

Warning Beware: Some MySQL table types (storage engines) do not support transactions. When writing transactional database code using a table type that does not support transactions, MySQL will pretend that a transaction was initiated successfully. In addition, any DDL queries issued will implicitly commit any pending transactions.

  • 这会在未来造成什么样的问题?

  • 如果我只使用 mysqli 会更好吗? (不确定是否有同样的问题)

最佳答案

我认为这个警告是因为所有类型的mysql存储引擎都不支持事务。不支持事务的引擎会立即自动提交数据。因此,请检查引擎列表及其工作差异。

mysql> SHOW ENGINES;
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| Engine     | Support | Comment                                                        | Transactions | XA   | Savepoints |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+
| InnoDB     | YES     | Supports transactions, row-level locking, and foreign keys     | YES          | YES  | YES        |
| MRG_MYISAM | YES     | Collection of identical MyISAM tables                          | NO           | NO   | NO         |
| BLACKHOLE  | YES     | /dev/null storage engine (anything you write to it disappears) | NO           | NO   | NO         |
| CSV        | YES     | CSV storage engine                                             | NO           | NO   | NO         |
| MEMORY     | YES     | Hash based, stored in memory, useful for temporary tables      | NO           | NO   | NO         |
| FEDERATED  | NO      | Federated MySQL storage engine                                 | NULL         | NULL | NULL       |
| ARCHIVE    | YES     | Archive storage engine                                         | NO           | NO   | NO         |
| MyISAM     | DEFAULT | Default engine as of MySQL 3.23 with great performance         | NO           | NO   | NO         |
+------------+---------+----------------------------------------------------------------+--------------+------+------------+

关于php - PDO 事务代码警告与 mysqli,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44149897/

相关文章:

Mysql TRIGGER ON UPDATE 函数

php - 在 Laravel 中将数组转换为 Eloquent 模型

php - 如何快速搭建一个php mysql站点?

java - 如何创建和使用外部 derby 数据库

java - 在文件系统中打开 Derby/JDBC 数据库

php - CODEIGNITER 从用户选择的值中选择数据库

php - SQL 解析错误 "on duplicate key update"

php - mysqli_fetch_all 不从一个特定表中检索记录

javascript - PHP/MySQL :Rank users by clicks

php - 如何优雅地死去?