我最近搬到了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