Skip to content

Commit

Permalink
php errors resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
AbmSourav committed Jul 25, 2023
1 parent 8037d68 commit 35c5ccf
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 61 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "codesvault/howdy-qb",
"description": "Mysql Query Builder for WordPress",
"version": "1.4.0",
"version": "1.5.0",
"minimum-stability": "stable",
"scripts": {
"test": "phpunit",
Expand Down
2 changes: 0 additions & 2 deletions src/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class DB extends QueryFactory
{
public static function select(...$columns): SelectInterface
{
dump(static::$driver);
$factory = new self(static::$driver);
$query = $factory->selectQuery();
$query = $query->columns(...$columns);
Expand All @@ -21,7 +20,6 @@ public static function select(...$columns): SelectInterface

public static function insert(string $table_name, array $data)
{
dump(static::$driver);
$factory = new self(static::$driver);
$factory->insertQuery($table_name, $data);
return $factory;
Expand Down
2 changes: 1 addition & 1 deletion src/Statement/Alter.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function getSql()
private function driver_exicute($sql)
{
$driver = $this->db;
if ($driver instanceof \wpdb) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($sql);
}

Expand Down
11 changes: 3 additions & 8 deletions src/Statement/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ public function __construct($db, string $table_name)
{
$this->db = $db;
$this->table_name = $table_name;
$this->wpdb_object = QueryFactory::getConfig();
if (empty(QueryFactory::getConfig())) {
global $wpdb;
$this->wpdb_object = $wpdb;
}

$this->start();
$this->sql['table_name'] = $this->get_table_name();
Expand Down Expand Up @@ -139,7 +134,7 @@ public function default($value): self

public function foreignKey(string $column, string $reference_table, string $reference_column): self
{
$table_name = $this->wpdb_object->prefix . $reference_table;
$table_name = Utilities::get_db_configs()->prefix . $reference_table;
$this->sql['foreignKey'] = "FOREIGN KEY ($column) REFERENCES $table_name ($reference_column)" ;
return $this;
}
Expand All @@ -151,7 +146,7 @@ protected function start()

protected function get_table_name()
{
return $this->wpdb_object->prefix . $this->table_name;
return Utilities::get_db_configs()->prefix . $this->table_name;
}

// get only sql query string
Expand All @@ -167,7 +162,7 @@ public function getSql()
private function driver_exicute($sql)
{
$driver = $this->db;
if ($driver instanceof \wpdb) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($sql);
}

Expand Down
11 changes: 2 additions & 9 deletions src/Statement/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,11 @@ class Delete implements DeleteInterface
public $sql = [];
protected $params = [];
protected $table_name;
protected $wpdb_object;

public function __construct($db, string $table_name)
{
$this->wpdb_object = QueryFactory::getConfig();
if (empty(QueryFactory::getConfig())) {
global $wpdb;
$this->wpdb_object = $wpdb;
}

$this->db = $db;
$this->table_name = $this->wpdb_object->prefix . $table_name;
$this->table_name = Utilities::get_db_configs()->prefix . $table_name;
}

protected function start()
Expand Down Expand Up @@ -72,7 +65,7 @@ public function dropIfExists()
private function driver_exicute($sql)
{
$driver = $this->db;
if ('wpdb' === QueryFactory::getDriver()) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($driver->prepare($sql, $this->params));
}

Expand Down
10 changes: 2 additions & 8 deletions src/Statement/Drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ class Drop implements DropInterface

public function __construct($db, string $table_name)
{
$this->wpdb_object = QueryFactory::getConfig();
if (empty(QueryFactory::getConfig())) {
global $wpdb;
$this->wpdb_object = $wpdb;
}

$this->db = $db;
$this->table_name = $this->wpdb_object->prefix . $table_name;
$this->table_name = Utilities::get_db_configs()->prefix . $table_name;
}

public function drop()
Expand All @@ -42,7 +36,7 @@ public function dropIfExists()
private function driver_exicute($sql)
{
$driver = $this->db;
if ('wpdb' === QueryFactory::getDriver()) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($sql);
}

Expand Down
14 changes: 2 additions & 12 deletions src/Statement/Insert.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,8 @@ private function insert_data()

private function driver_exicute($sql)
{
dump($sql, $this->params);
$driver = $this->db;
if ($driver instanceof \wpdb) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($driver->prepare($sql, $this->params));
}

Expand All @@ -61,18 +60,9 @@ private function start()

private function get_table_name()
{
return $this->getTablePrefix()->prefix . $this->table_name;
return Utilities::get_db_configs()->prefix . $this->table_name;
}

private function getTablePrefix()
{
if (empty(QueryFactory::getConfig())) {
global $wpdb;
return $wpdb;
}
return QueryFactory::getConfig();
}

private function get_columns()
{
if (empty($this->data)) return;
Expand Down
14 changes: 4 additions & 10 deletions src/Statement/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ class Select implements SelectInterface
protected $sql = [];
protected $params = [];
protected $table_name;
protected $wpdb_object;
private $raw_count = 0;

public function __construct($db)
{
$this->db = $db;
$this->wpdb_object = QueryFactory::getConfig();
if (empty(QueryFactory::getConfig())) {
global $wpdb;
$this->wpdb_object = $wpdb;
}
}

protected function start()
Expand Down Expand Up @@ -71,7 +65,7 @@ public function alias(string $name): self

public function from(string $table_name): self
{
$this->sql['table_name'] = 'FROM ' . $this->wpdb_object->prefix . $table_name;
$this->sql['table_name'] = 'FROM ' . Utilities::get_db_configs()->prefix . $table_name;
return $this;
}

Expand Down Expand Up @@ -158,10 +152,10 @@ private function setJoin($table_name, string $col1 = null, string $col2 = null,
$table_names = [];
if (is_array($table_name)) {
foreach ($table_name as $table) {
$table_names[] = $this->wpdb_object->prefix . $table;
$table_names[] = Utilities::get_db_configs()->prefix . $table;
}
} else {
$table_names[] = $this->wpdb_object->prefix . $table_name;
$table_names[] = Utilities::get_db_configs()->prefix . $table_name;
}

$table = '';
Expand Down Expand Up @@ -224,7 +218,7 @@ private function fetch($query, array $args = [])
private function driver_exicute($sql, $placeholders)
{
$driver = $this->db;
if ($driver instanceof \wpdb) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
if (empty($placeholders)) {
return $driver->get_results($sql, ARRAY_A);
}
Expand Down
23 changes: 13 additions & 10 deletions src/Statement/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,20 @@ class Update implements UpdateInterface
public $sql = [];
protected $params = [];
protected $table_name;
protected $wpdb_object;

public function __construct($db, string $table_name, array $data)
{
$this->wpdb_object = QueryFactory::getConfig();
if (empty(QueryFactory::getConfig())) {
global $wpdb;
$this->wpdb_object = $wpdb;
}
$this->db = $db;

$this->db = $db;
$this->data = $data;
$this->table_name = $this->wpdb_object->prefix . $table_name;
$this->table_name = $this->get_table_prefix()->prefix . $table_name;
$this->sql['set_columns'] = $this->set_columns();
}

private function driver_exicute($sql)
{
$driver = $this->db;
if ('wpdb' === QueryFactory::getDriver()) {
if (class_exists('wpdb') && $driver instanceof \wpdb) {
return $driver->query($driver->prepare($sql, $this->params));
}

Expand Down Expand Up @@ -69,6 +63,15 @@ public function getSql()
return $query;
}

private function get_table_prefix()
{
if (empty(QueryFactory::getConfig())) {
global $wpdb;
return $wpdb;
}
return QueryFactory::getConfig();
}

protected function start()
{
$this->sql['start'] = 'UPDATE ' . $this->table_name;
Expand All @@ -92,7 +95,7 @@ public function where($column, string $operator = null, $value = null): self
call_user_func( $column, $this );
return $this;
}
$this->sql['where'] = 'WHERE ' . $column . ' ' . $operator . ' ' . Utilities::get_placeholder();
$this->sql['where'] = 'WHERE ' . $column . ' ' . $operator . ' ' . Utilities::get_placeholder($this->db, $value);
$this->params[] = $value;
return $this;
}
Expand Down
9 changes: 9 additions & 0 deletions src/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ public static function get_placeholder($db, $value)
}
return "?";
}

public static function get_db_configs()
{
if (empty(QueryFactory::getConfig())) {
global $wpdb;
return $wpdb;
}
return QueryFactory::getConfig();
}
}

0 comments on commit 35c5ccf

Please sign in to comment.