1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
public function select($sql): array
{
try {
if ($this->isModeSQLDirect()) {
$this->stmt = self::pdo()->query($sql); // pour info, je passe là
} else {
$this->prepareAndAttachValuesOrParams($sql);
$this->stmt->execute();
}
$ret=$this->stmt->fetchAll();
self::closeCursor(); //modif 23/10/20
return $ret;
} catch (Exception $e) {
if ($this->debug) {
var_dump($sql);
}
error_log('PPP::select - '.$e->getMessage());
throw $e;
}
}
public static function pdo(): PDO
{
if (self::$pdo === null) {
self::connect();
}
return self::$pdo;
}
protected static function connect(
string $scheme = DB_SCHEME, string $host = DB_HOST, string $database = DB_NAME, string $user = DB_USER,
string $pwd = DB_PWD, string $port = DB_PORT, string $timeout = DB_TIMEOUT, array $pdo_params = DB_PDO_PARAMS,
array $dsn_params = DB_DSN_PARAMS
) {
$dsn = "{$scheme}:host={$host};dbname={$database};";
if ((int)($port)) {
$dsn .= 'port='.(int)$port.';';
}
if ((int)$timeout) {
$dsn .= 'connect_timeout='.(int)$timeout.';';
}
if ( ! empty($dsn_params)) {
$dsn .= implode(';', $dsn_params).';';
}
$params = $pdo_params + [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
];
try {
self::$pdo = new PDO($dsn, $user, $pwd, $params);
} catch (Exception $e) {
throw $e;
}
}
public function closeCursor()
{
if (isset($this->stmt)) {
$this->stmt->closeCursor();
}
} |
Partager