의 경우 구성 :PDO 내가 PDO 연결 기능의이 종류를 사용하고 실패
class MyPDO extends PDO{
const DB_HOST='localhost';
const DB_PORT='3306';
const DB_NAME='testdb';
const DB_USER='root';
const DB_PASS='root';
public function __construct($options=null){
parent::__construct('mysql:host='.MyPDO::DB_HOST.';port='.MyPDO::DB_PORT.';dbname='.MyPDO::DB_NAME,MyPDO::DB_USER,MyPDO::DB_PASS,$options);
}
public function query($query){ //secured query with prepare and execute
$args = func_get_args();
array_shift($args); //first element is not an argument but the query itself, should removed
$reponse = parent::prepare($query);
$reponse->execute($args);
return $reponse;
}
}
이제 연결 및 쿼리가 잘 작동하고 모든 것이 매우 중요하지만, 경우에 MySQL 서버 스크립트 아래의 경우 전 이 연결 기능을 사용하면 작업이 중지됩니다. 대신 mysql 서버가 응답하지 않거나 mysql 설정이 잘못 설정된 경우 일부 메시지를 반환하고 싶습니다.
내가
if(new MyPDO===false){echo "The database is down currently. Please try again later."}
같은 일을 시도했습니다하지만 그건 작동하지 않습니다. 제발 도와주세요. 내가 필요로하는 것은 mysql 연결이 전체 스크립트를 깨뜨리고 빈 페이지 (현재와 같이)를 보여주는 대신 사용할 수없는 경우에 메시지를 표시하는 것입니다.
코드 끝에서 연결을 닫아야합니까? 예를 들어 atm 어디서나 db connection이 필요합니다. $ db = new MyPDO; 일부 코드 및 쿼리 등, 그리고 $ db = null보다; 그래서 모든 연결을 열어 두지 마십시오. – EvilNabster
코드 끝에서 $ db = null을 사용하지 마십시오. 모든 것이 훌륭하게 작동합니다. – EvilNabster