2 Commits
1.0 ... master

Author SHA1 Message Date
eaac290caa src/wp_db_light.php aktualisiert 2025-01-29 07:45:01 +01:00
8e1cdaedd2 feat: bugfix wpdb 2024-12-04 22:36:10 +01:00
3 changed files with 23 additions and 10 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,20 +1,31 @@
<?php
require_once(dirname(__FILE__) . '/wp_db.php');
namespace WP_DB;
class WP_DB_LIGHT extends WP_DB
{
public $dbName;
public $path = false;
function connect()
{
$databaseFile = '/sql/'.$this->dbName.'.db';
$pdo = new PDO("sqlite:$databaseFile");
$path = '/sql/';
if ($this->path) {
$path .= $this->path . "/";
}
$databaseFile = $path . $this->dbName . '.db';
$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;
}
function createPathIfnotExists($folderPath)
{
if (!file_exists($folderPath)) {
mkdir($folderPath, 0777, true);
}
}
}