这是我的代码:
$dbh = new PDO('mysql:host=localhost;dbname=diffsrc', 'root', '******', [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$path = 'C:/dumps/test.sql';
$sql = file_get_contents($path);
$dbh->query($sql);
echo 'OK';
和dump(test.sql)是:
-- phpMyAdmin SQL Dump
-- version 4.1.13
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 21, 2014 at 09:25 AM
-- Server version: 5.5.23
-- PHP Version: 5.4.28
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `diffdst`
--
-- --------------------------------------------------------
--
-- Table structure for table `dfgxfcghfdxgh`
--
DROP TABLE IF EXISTS `dfgxfcghfdxgh`;
CREATE TABLE IF NOT EXISTS `dfgxfcghfdxgh` (
`asdf` int(11) NOT NULL,
`asdffg` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Triggers `dfgxfcghfdxgh`
--
DROP TRIGGER IF EXISTS `zzz`;
DELIMITER //
CREATE TRIGGER `zzz` BEFORE INSERT ON `dfgxfcghfdxgh`
FOR EACH ROW begin
INSERT INTO zz (z1,z2)
values (1, 2);
end
//
DELIMITER ;
-- --------------------------------------------------------
--
-- Table structure for table `zz`
--
DROP TABLE IF EXISTS `zz`;
CREATE TABLE IF NOT EXISTS `zz` (
`z1` int(11) NOT NULL,
`z2` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
问题是当我执行那个PHP脚本时,我看到'OK'。所以没有例外。
但是当我查看创建的数据库时:没有触发器而没有表zz
。看起来执行在触发器上停止。
即使我把这个转储放入任何其他错误,例如错误的关键字等。它只是默默地失败而没有感知或其他错误解释。如果我运行简单的sql,例如:select * from none
- exception apears