0
これはOOPを使用したデータベース接続です。実行する関数に何が間違っているのか教えてください。データベースに同じ値を更新する際にエラーが発生しました
<?php
class db{
private $conn;
private $host;
private $user;
private $password;
private $dbname;
private $port;
private $debug;
function __construct($params=array())
{
$this->conn = false;
$this->host = "localhost";
$this->user = "root";
$this->password = "mysql";
$this->dbname = "icecreams";
$this->port = "";
$this->debug = true;
$this->connect();
}
function __destruct()
{
$this->disconnect();
// TODO: Implement __destruct() method.
}
function connect(){
if(!$this->conn){
try {
$this->conn = new PDO("mysql:host=$this->host;dbname=$this->dbname",$this->user,$this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND =>'SET NAMES utf8'));
}
catch (Exception $e){
die('Errer :'.$e->getMessage());
}
if(!$this->conn){
$this->status_fatal = true;
echo 'Connection BDD failed';
die();
}
else{
$this->status_fatal = false;
}
}
return $this->conn;
}
function disconnect(){
if($this->conn){
$this->conn = null;
}
}
function execute($query){
if(!$response = $this->conn->exec($query)){
echo 'PDO::errorInfo()';
echo '</br>';
echo 'error SQL:'.$query;
die();
}
return $response;
}}
私は別の値を更新した場合、それが更新され、と私は同じ値で更新を与える場合には、PDO ::エラー情報とエラーSQLを示しています。execte機能を形成します。
感謝、この**解決**私の問題。 –