PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.6
ShopBuilder – WooCommerce Builder For Elementor v3.2.6
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / vendor / codesvault / howdy-qb / src / Statement / Delete.php

Delete.php in ShopBuilder – WooCommerce Builder For Elementor 3.2.6, at vendor/codesvault/howdy-qb/src/Statement/Delete.php

85 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace CodesVault\Howdyqb\Statement;
4
5 use CodesVault\Howdyqb\Api\DeleteInterface;
6 use CodesVault\Howdyqb\Clause\WhereClause;
7 use CodesVault\Howdyqb\SqlGenerator;
8 use CodesVault\Howdyqb\Utilities;
9
10 class Delete implements DeleteInterface
11 {
12 // bring all SQL Clause
13 use WhereClause;
14
15 protected $db;
16 public $sql = [];
17 protected $params = [];
18 protected $table_name;
19
20 public function __construct($db, string $table_name)
21 {
22 $this->db = $db;
23 $this->table_name = Utilities::get_db_configs()->prefix . $table_name;
24 }
25
26 protected function start()
27 {
28 $this->sql['start'] = 'DELETE FROM ' . $this->table_name;
29 }
30
31 public function drop()
32 {
33 $this->sql['drop'] = 'DROP TABLE ' . $this->table_name;
34 return $this;
35 }
36
37 public function dropIfExists()
38 {
39 $this->sql['drop'] = 'DROP TABLE IF EXISTS ' . $this->table_name;
40 return $this;
41 }
42
43 private function driver_exicute($sql)
44 {
45 $driver = $this->db;
46 if (class_exists('wpdb') && $driver instanceof \wpdb) {
47 if (empty($this->params)) {
48 return $driver->query($sql);
49 }
50 return $driver->query($driver->prepare($sql, $this->params));
51 }
52
53 $data = $driver->prepare($sql);
54 try {
55 return $data->execute($this->params);
56 } catch (\PDOException $exception) {
57 Utilities::throughException($exception);
58 }
59 }
60
61 private function delete_data()
62 {
63 $query = SqlGenerator::delete($this->sql);
64
65 return $this->driver_exicute($query);
66 }
67
68 // get only sql query string
69 public function getSql()
70 {
71 $this->start();
72 $query = [
73 'query' => SqlGenerator::delete($this->sql),
74 'params' => $this->params,
75 ];
76 return $query;
77 }
78
79 public function execute()
80 {
81 $this->start();
82 $this->delete_data();
83 }
84 }
85