我最近搬到了MariaDB,因为自从MySQL 5.6以来,它对我来说已经失败了很多。我不能用我的PHP脚本插入到MariaDB表
MariaDB完美地工作,但在新项目中,我无法用PHP脚本将数据插入数据库。我只能手动插入。我没有对使用MySQL的脚本进行更改。
INSERT语句是:
INSERT INTO participantes (nome, curso, email, equipe) VALUES (:nome, :curso, :email, :equipe);
,哪些应该插入脚本是:
$stmt = $this->dbh->prepare($this->SQL_INSERT);
$nome = $participante->nome();
$curso = $participante->curso();
$email = $participante->email();
$equipe = $participante->equipe();
$stmt->bindParam(':nome', $nome);
$stmt->bindParam(':curso', $curso);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':equipe', $equipe);
$stmt->execute();
的 “PARTICIPANTE” 函数返回要使用的数据,没有任何问题。所有内容都位于try/catch块内,该块不报告任何异常。
我PDO类如下:
class Connection extends PDO {
private $dsn = 'mysql:host=localhost;port=3307;dbname=dacu';
private $usr = 'dacu';
private $pwd = 'my password';
public $handle = null;
function __construct() {
try {
if ($this->handle == null) {
$dbh = new PDO($this->dsn, $this->usr, $this->pwd);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->handle = $dbh;
return $this->handle;
}
}
catch (PDOException $e) {
throw new Exception('Não foi possível conectar-se ao banco de dados: ' . $e->getMessage());
}
catch (Exception $e) {
throw new Exception('Um erro não identificado ocorreu: ' . $e->getMessage());
}
}
}
而且使用控制器 - >插入给我:
Warning: PDO::prepare(): SQLSTATE[00000]: No error: PDO constructor was not called in C:\Webserver\Files\dacu\controller\EquipesController.php on line 25
我可以根据需要对引擎收录邮编,只问。
不是“PHP”,而是“*我的代码*不插入到MariaDB的表:”如果你想了解你的代码的codereivew – 2013-05-04 19:29:11
,它可能更适合于代码审查网站。这里的网站最适合具体的编程问题。 – hakre 2013-05-04 19:31:40
数据库中的所有被引用的列字符串? – 2013-05-04 19:32:59