1 Commits
1.0 ... 2.0

Author SHA1 Message Date
8e1cdaedd2 feat: bugfix wpdb 2024-12-04 22:36:10 +01:00
3 changed files with 11 additions and 8 deletions

View File

@@ -1,7 +1,7 @@
{ {
"name": "vorbild/wpdb-alternative", "name": "vorbild/wpdb-alternative",
"description": "Gives you access to main wpdb->functions", "description": "Gives you access to main wpdb->functions",
"version": "1.0", "version": "2.0",
"type": "library", "type": "library",
"authors": [ "authors": [
{ {

View File

@@ -1,5 +1,7 @@
<?php <?php
namespace WP_DB;
class WP_DB class WP_DB
{ {
@@ -13,15 +15,15 @@ class WP_DB
function connect() function connect()
{ {
$options = [ $options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, \PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, \PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false, \PDO::ATTR_EMULATE_PREPARES => false,
]; ];
$dsn = "mysql:host=$this->host;dbname=$this->db;charset=utf8"; $dsn = "mysql:host=$this->host;dbname=$this->db;charset=utf8";
try { try {
$pdo = new PDO($dsn, $this->user, $this->pass, $options); $pdo = new \PDO($dsn, $this->user, $this->pass, $options);
} catch (\PDOException $e) { } catch (\PDOException $e) {
throw new \PDOException($e->getMessage(), (int)$e->getCode()); throw new \PDOException($e->getMessage(), (int)$e->getCode());
} }

View File

@@ -1,5 +1,6 @@
<?php <?php
require_once(dirname(__FILE__) . '/wp_db.php');
namespace WP_DB;
class WP_DB_LIGHT extends WP_DB class WP_DB_LIGHT extends WP_DB
{ {
@@ -8,10 +9,10 @@ class WP_DB_LIGHT extends WP_DB
function connect() function connect()
{ {
$databaseFile = '/sql/'.$this->dbName.'.db'; $databaseFile = '/sql/'.$this->dbName.'.db';
$pdo = new PDO("sqlite:$databaseFile"); $pdo = new \PDO("sqlite:$databaseFile");
// Set the error mode to exception // Set the error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return $pdo; return $pdo;
} }