feat: bugfix wpdb

This commit is contained in:
2024-12-04 22:36:10 +01:00
parent 0ebaca6d89
commit 8e1cdaedd2
3 changed files with 11 additions and 8 deletions

View File

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

View File

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

View File

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