D.h. du musst parent::__construct() verwenden, nicht new PDO().
DAS war der entscheidende Hinweis!
<?php
class RPDO extends PDO {
protected $arErrors = [];
protected $errorTypes = [
0,
E_USER_NOTICE,
E_USER_WARNING,
E_USER_ERROR
];
function __construct ( $string, $errType=E_USER_ERROR ) {
if ( ! in_array( $errType, $this-> errorTypes ) ) {
trigger_error( '$errType has to be ' . implode (' or ', $this ->errorTypes ), E_USER_ERROR );
}
if ( 0 === strpos( $string, 'sqlite:') ) {
$filename = trim( substr ( $string, 7, strlen( $string ) ) );
$dirname = dirname( $filename );
if ( '' == $dirname ) {
$dirname = './';
}
if ( ! is_writable ( $dirname ) ) {
$eMsg = 'The directory "' . $dirname . ' has to be writable.';
$this -> arErrors[] = $eMsg;
}
if ( ! is_file( $filename ) ) {
$eMsg = 'the file "' . $filename . '" not exits.';
$this -> arErrors[] = $eMsg;
} else {
if ( ! is_readable( $filename ) ) {
$eMsg = 'the file "' . $filename . '" is not readable';
$this -> arErrors[] = $eMsg;
}
if ( ! is_writable( $filename ) ) {
$eMsg = 'the file "' . $filename . '" is not writable';
$this -> arErrors[] = $eMsg;
}
}
if ( count( $this -> arErrors ) ) {
if ( 0 != $errType ) {
trigger_error( implode( ' and ', $this -> arErrors ) , $errType );
}
}
try {
parent::__construct( 'sqlite:' . $filename );
} catch( PDOException $e ) {
trigger_error( $e -> __toString(), E_USER_ERROR );
}
}
}
}
/** Tests: **/
#/*
$pdo = new RPDO ( 'sqlite: values.sqlite3', E_USER_NOTICE );
#$pdo = new RPDO ( 'sqlite:readonly.sqlite3', E_USER_NOTICE );
#$pdo = new RPDO ( 'sqlite:readonly.sqlite3', E_USER_ERROR );
$pdo = new RPDO ( 'sqlite:leer', E_USER_ERROR );
$sql = 'SELECT id, timestamp, url_effective FROM speed LIMIT 2';
try {
$stmt = $pdo->prepare( $sql );
if ( $stmt ) {
$stmt -> execute();
while ( $result = $stmt -> fetch( PDO::FETCH_ASSOC ) ) {
print_r( $result );
}
} else {
trigger_error( 'SQL-Error: ' . ( $pdo->errorInfo() )[2] . ' in "' . $sql .'"', E_USER_ERROR );
}
} catch ( PDOException $e ) {
trigger_error( $e -> __toString(), E_USER_ERROR );
}
# */
hasErrors/getErrors würde ich auch nicht machen.
[x] Deleted, wird nicht gebraucht.