다른 유사한 링크를 사용하여 내 질문에 답을 얻으려고했지만 couldn 해결 안해. 다른 질문은 PHP 클래스가 있다고 인정하고이를 사용합니다. 필자의 경우 이미 PHP 클래스가 있으며, 여전히 동일한 오류가 발생합니다. 내가 사용 culttt.com/2012/10/01/roll-your-own-pdo-php-class/PHP 치명적 오류 : admin includes html database.class.php에있는 객체가 아닌 객체에서 prepare() 함수를 호출하십시오.
내 경우:
나는 다음 링크의 설명에 따라이 클래스를 만든 MS SQL.첫 번째 시도 :
는 다음 아파치 서버에 다음과 같은 결과를 반영 다른 파일 (phppdo.php)에서 다음 PHP 코드를 실행 database.class.php
class Database{
private $dbtype = DB_TYPE;
private $host = DB_HOST;
private $user = DB_USER;
private $pass = DB_PASS;
private $dbname = DB_NAME;
private $dbh;
private $error;
private $stmt;
public function __construct(){
// Set DSN
if ($this->dbtype == 'mysql') {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbname;
}
if ($this->dbtype == 'sqlsrv') {
$dsn = 'sqlsrv:server=' . $this->host . ';Database=' . $this->dbname;
}
// Set options
$options = array(
PDO::ATTR_PERSISTENT => true,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
// Create a new PDO instanace
try{
$this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
}
// Catch any errors
catch(PDOException $e){
$this->error = $e->getMessage();
}
}
public function query($query){
$this->stmt = $this->dbh->prepare($query);
}
public function bind($param, $value, $type = null){
if (is_null($type)) {
switch (true) {
case is_int($value):
$type = PDO::PARAM_INT;
break;
case is_bool($value):
$type = PDO::PARAM_BOOL;
break;
case is_null($value):
$type = PDO::PARAM_NULL;
break;
default:
$type = PDO::PARAM_STR;
}
}
$this->stmt->bindValue($param, $value, $type);
}
public function execute(){
return $this->stmt->execute();
}
public function resultset(){
$this->execute();
return $this->stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function single(){
$this->execute();
return $this->stmt->fetch(PDO::FETCH_ASSOC);
}
public function rowCount(){
return $this->stmt->rowCount();
}
public function lastInsertId(){
return $this->dbh->lastInsertId();
}
public function beginTransaction(){
return $this->dbh->beginTransaction();
}
public function endTransaction(){
return $this->dbh->commit();
}
public function cancelTransaction(){
return $this->dbh->rollBack();
}
public function debugDumpParams(){
return $this->stmt->debugDumpParams();
}
}
의 코드 phppdo.php를 실행하면 결과가 반영됩니다.
phppdo.php을 실행함으로써 다음과 같은 오차 반영번째 시도 :
가 은 치명적인 오류가: C의 비 객체() 제조 멤버 함수 호출 : \ XAMPP \ htdocs를 \ sattest \ 관리 \ 포함을 \ html \ database.class.php on line 45
phppdo.php를 세 번째로 실행하면 Apache 서버가 충돌하고 Apache 서비스가 다시 시작됩니다.
네 번째 시도는 첫 번째 시도만큼 결과를 잘 보여줍니다. 테스트를 위해이 파일을 반복해서 실행하면이주기가 반복됩니다.
[Mon Nov 03 09:35:27.883145 2014] [core:warn] [pid 14276:tid 256] AH00098: pid file C:/xampp/apache/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
[Mon Nov 03 09:35:28.796237 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00455: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 configured -- resuming normal operations
[Mon Nov 03 09:35:28.796237 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00456: Server built: Aug 18 2012 12:41:37
[Mon Nov 03 09:35:28.796237 2014] [core:notice] [pid 14276:tid 256] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Mon Nov 03 09:35:28.799237 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00418: Parent: Created child process 4528
[Mon Nov 03 09:35:30.490406 2014] [mpm_winnt:notice] [pid 4528:tid 268] AH00354: Child: Starting 150 worker threads.
[Mon Nov 03 09:35:36.041961 2014] [:error] [pid 4528:tid 1756] [client 127.0.0.1:63411] script 'C:/xampp/htdocs/sattest/nzta-forms/admin/pdodb-tutorial.php' not found or unable to stat
[Mon Nov 03 09:36:40.478404 2014] [:error] [pid 4528:tid 1716] [client 127.0.0.1:63418] PHP Fatal error: Call to a member function prepare() on a non-object in C:\\xampp\\htdocs\\sattest\\nzta-forms\\admin\\includes\\html\\database.class.php on line 45
[Mon Nov 03 09:36:44.453802 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00428: Parent: child process exited with status 3221225477 -- Restarting.
[Mon Nov 03 09:36:45.002856 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00455: Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7 configured -- resuming normal operations
[Mon Nov 03 09:36:45.002856 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00456: Server built: Aug 18 2012 12:41:37
[Mon Nov 03 09:36:45.002856 2014] [core:notice] [pid 14276:tid 256] AH00094: Command line: 'c:\\xampp\\apache\\bin\\httpd.exe -d C:/xampp/apache'
[Mon Nov 03 09:36:45.004857 2014] [mpm_winnt:notice] [pid 14276:tid 256] AH00418: Parent: Created child process 14456
[Mon Nov 03 09:36:46.597016 2014] [mpm_winnt:notice] [pid 14456:tid 268] AH00354: Child: Starting 150 worker threads.
도와 주셔서 감사합니다 사전에 t : 다음
는// Include database class
include('database.class.php');
// Define configuration
define("DB_TYPE", "sqlsrv"); // Values allowed: sqlsrv, mysql, sqlite
define("DB_HOST", "localhost");
define("DB_USER", "dbuser");
define("DB_PASS", "password");
define("DB_NAME", "dbname");
$database = new Database();
$database->query('SELECT * FROM incidents WHERE incident_id = 1 ');
$database->execute();
$rows = $database->resultset();
echo "<pre>";
print_r($rows);
echo "</pre>";
아파치 오류 로그입니다. 나는 이것을 가능한 빨리 해결할 필요가있다. 튜토리얼은 바보
그건 ...
~ Satinder
메이트, 그 튜토리얼은 어리석은 ... 왜 PDO를 장식하고 새로운 객체의 기능/기능을 제거하겠습니까? 그리고 생성자는 예외를 먹고 있습니다. 그것은 $ this-> error (사적인)에 기록하지만 변수 – Tivie