@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | - /** |
|
| 4 | - * Generic SQL Driver Related Functionality |
|
| 5 | - * @author Joe Huss <[email protected]> |
|
| 6 | - * @copyright 2025 |
|
| 7 | - * @package MyAdmin |
|
| 8 | - * @category SQL |
|
| 9 | - */ |
|
| 3 | + /** |
|
| 4 | + * Generic SQL Driver Related Functionality |
|
| 5 | + * @author Joe Huss <[email protected]> |
|
| 6 | + * @copyright 2025 |
|
| 7 | + * @package MyAdmin |
|
| 8 | + * @category SQL |
|
| 9 | + */ |
|
| 10 | 10 | |
| 11 | 11 | namespace MyDb; |
| 12 | 12 | |
@@ -17,184 +17,184 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | class Loader |
| 19 | 19 | { |
| 20 | - /* public: connection parameters */ |
|
| 21 | - public $Type = 'mysqli'; |
|
| 22 | - public $host = 'localhost'; |
|
| 23 | - public $database = ''; |
|
| 24 | - public $user = ''; |
|
| 25 | - public $password = ''; |
|
| 26 | - |
|
| 27 | - /* public: configuration parameters */ |
|
| 28 | - public $autoStripslashes = false; |
|
| 29 | - public $Debug = 0; // Set to 1 for debugging messages. |
|
| 30 | - public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning) |
|
| 31 | - |
|
| 32 | - /* public: result array and current row number */ |
|
| 33 | - public $Record = []; |
|
| 34 | - public $Row; |
|
| 35 | - |
|
| 36 | - /* public: current error number and error text */ |
|
| 37 | - public $Errno = 0; |
|
| 38 | - public $Error = ''; |
|
| 39 | - |
|
| 40 | - public $type; |
|
| 41 | - |
|
| 42 | - /* private: link and query handles */ |
|
| 43 | - public $linkId = 0; |
|
| 44 | - public $queryId = 0; |
|
| 45 | - |
|
| 46 | - public $characterSet = ''; |
|
| 47 | - public $collation = ''; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Constructs the db handler, can optionally specify connection parameters |
|
| 51 | - * |
|
| 52 | - * @param string $Type Optional The database type mysql/mysqli/pdo/adodb/pgsql |
|
| 53 | - * @param string $database Optional The database name |
|
| 54 | - * @param string $user Optional The username to connect with |
|
| 55 | - * @param string $password Optional The password to use |
|
| 56 | - * @param string $host Optional The hostname where the server is, or default to localhost |
|
| 57 | - * @param string $query Optional query to perform immediately |
|
| 58 | - */ |
|
| 59 | - public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '') |
|
| 60 | - { |
|
| 61 | - $this->Type = $Type; |
|
| 62 | - if (!defined('db')) { |
|
| 63 | - switch ($this->Type) { |
|
| 64 | - case 'mysqli': |
|
| 65 | - include_once 'class.db_mysqli.inc.php'; |
|
| 66 | - break; |
|
| 67 | - case 'mysql': |
|
| 68 | - include_once 'class.db_mysql.inc.php'; |
|
| 69 | - break; |
|
| 70 | - case 'adodb': |
|
| 71 | - include_once 'class.db_adodb.inc.php'; |
|
| 72 | - break; |
|
| 73 | - case 'mdb2': |
|
| 74 | - include_once 'class.db_mdb2.inc.php'; |
|
| 75 | - break; |
|
| 76 | - case 'pdo': |
|
| 77 | - include_once 'class.db_pdo.inc.php'; |
|
| 78 | - break; |
|
| 79 | - case 'pgsql': |
|
| 80 | - include_once 'class.db_pgsql.inc.php'; |
|
| 81 | - break; |
|
| 82 | - default: |
|
| 83 | - $this->log('Could not find DB class '.$this->Type, __LINE__, __FILE__); |
|
| 84 | - break; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - $this->database = $database; |
|
| 88 | - $this->user = $user; |
|
| 89 | - $this->password = $password; |
|
| 90 | - $this->host = $host; |
|
| 91 | - if ($query != '') { |
|
| 92 | - $this->query($query); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * @param $message |
|
| 98 | - * @param string $line |
|
| 99 | - * @param string $file |
|
| 100 | - */ |
|
| 101 | - public function log($message, $line = '', $file = '') |
|
| 102 | - { |
|
| 103 | - error_log($message); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @return int |
|
| 108 | - */ |
|
| 109 | - public function linkId() |
|
| 110 | - { |
|
| 111 | - return $this->linkId; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * @return int |
|
| 116 | - */ |
|
| 117 | - public function queryId() |
|
| 118 | - { |
|
| 119 | - return $this->queryId; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * @param $str |
|
| 124 | - * @return string |
|
| 125 | - */ |
|
| 126 | - public function dbAddslashes($str) |
|
| 127 | - { |
|
| 128 | - if (!isset($str) || $str == '') { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return addslashes($str); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * db:qr() |
|
| 137 | - * |
|
| 138 | - * alias of queryReturn() |
|
| 139 | - * |
|
| 140 | - * @param mixed $query SQL Query to be used |
|
| 141 | - * @param string $line optionally pass __LINE__ calling the query for logging |
|
| 142 | - * @param string $file optionally pass __FILE__ calling the query for logging |
|
| 143 | - * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
|
| 144 | - */ |
|
| 145 | - public function qr($query, $line = '', $file = '') |
|
| 146 | - { |
|
| 147 | - return $this->queryReturn($query, $line, $file); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * error handling |
|
| 152 | - * |
|
| 153 | - * @param mixed $msg |
|
| 154 | - * @param string $line |
|
| 155 | - * @param string $file |
|
| 156 | - * @return void |
|
| 157 | - */ |
|
| 158 | - public function halt($msg, $line = '', $file = '') |
|
| 159 | - { |
|
| 160 | - $this->unlock(false); |
|
| 161 | - |
|
| 162 | - if ($this->haltOnError == 'no') { |
|
| 163 | - return; |
|
| 164 | - } |
|
| 165 | - $this->haltmsg($msg); |
|
| 166 | - |
|
| 167 | - if ($file) { |
|
| 168 | - error_log("File: $file"); |
|
| 169 | - } |
|
| 170 | - if ($line) { |
|
| 171 | - error_log("Line: $line"); |
|
| 172 | - } |
|
| 173 | - if ($this->haltOnError != 'report') { |
|
| 174 | - echo '<p><b>Session halted.</b>'; |
|
| 175 | - // FIXME! Add check for error levels |
|
| 176 | - if (isset($GLOBALS['tf'])) { |
|
| 177 | - $GLOBALS['tf']->terminate(); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * @param $msg |
|
| 184 | - */ |
|
| 185 | - public function haltmsg($msg) |
|
| 186 | - { |
|
| 187 | - $this->log("Database error: $msg", __LINE__, __FILE__); |
|
| 188 | - if ($this->Errno != '0' || $this->Error != '()') { |
|
| 189 | - $this->log('SQL Error: '.$this->Errno.' ('.$this->Error.')', __LINE__, __FILE__); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @return array |
|
| 195 | - */ |
|
| 196 | - public function indexNames() |
|
| 197 | - { |
|
| 198 | - return []; |
|
| 199 | - } |
|
| 20 | + /* public: connection parameters */ |
|
| 21 | + public $Type = 'mysqli'; |
|
| 22 | + public $host = 'localhost'; |
|
| 23 | + public $database = ''; |
|
| 24 | + public $user = ''; |
|
| 25 | + public $password = ''; |
|
| 26 | + |
|
| 27 | + /* public: configuration parameters */ |
|
| 28 | + public $autoStripslashes = false; |
|
| 29 | + public $Debug = 0; // Set to 1 for debugging messages. |
|
| 30 | + public $haltOnError = 'yes'; // "yes" (halt with message), "no" (ignore errors quietly), "report" (ignore error, but spit a warning) |
|
| 31 | + |
|
| 32 | + /* public: result array and current row number */ |
|
| 33 | + public $Record = []; |
|
| 34 | + public $Row; |
|
| 35 | + |
|
| 36 | + /* public: current error number and error text */ |
|
| 37 | + public $Errno = 0; |
|
| 38 | + public $Error = ''; |
|
| 39 | + |
|
| 40 | + public $type; |
|
| 41 | + |
|
| 42 | + /* private: link and query handles */ |
|
| 43 | + public $linkId = 0; |
|
| 44 | + public $queryId = 0; |
|
| 45 | + |
|
| 46 | + public $characterSet = ''; |
|
| 47 | + public $collation = ''; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Constructs the db handler, can optionally specify connection parameters |
|
| 51 | + * |
|
| 52 | + * @param string $Type Optional The database type mysql/mysqli/pdo/adodb/pgsql |
|
| 53 | + * @param string $database Optional The database name |
|
| 54 | + * @param string $user Optional The username to connect with |
|
| 55 | + * @param string $password Optional The password to use |
|
| 56 | + * @param string $host Optional The hostname where the server is, or default to localhost |
|
| 57 | + * @param string $query Optional query to perform immediately |
|
| 58 | + */ |
|
| 59 | + public function __construct($Type = '', $database = '', $user = '', $password = '', $host = 'localhost', $query = '') |
|
| 60 | + { |
|
| 61 | + $this->Type = $Type; |
|
| 62 | + if (!defined('db')) { |
|
| 63 | + switch ($this->Type) { |
|
| 64 | + case 'mysqli': |
|
| 65 | + include_once 'class.db_mysqli.inc.php'; |
|
| 66 | + break; |
|
| 67 | + case 'mysql': |
|
| 68 | + include_once 'class.db_mysql.inc.php'; |
|
| 69 | + break; |
|
| 70 | + case 'adodb': |
|
| 71 | + include_once 'class.db_adodb.inc.php'; |
|
| 72 | + break; |
|
| 73 | + case 'mdb2': |
|
| 74 | + include_once 'class.db_mdb2.inc.php'; |
|
| 75 | + break; |
|
| 76 | + case 'pdo': |
|
| 77 | + include_once 'class.db_pdo.inc.php'; |
|
| 78 | + break; |
|
| 79 | + case 'pgsql': |
|
| 80 | + include_once 'class.db_pgsql.inc.php'; |
|
| 81 | + break; |
|
| 82 | + default: |
|
| 83 | + $this->log('Could not find DB class '.$this->Type, __LINE__, __FILE__); |
|
| 84 | + break; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + $this->database = $database; |
|
| 88 | + $this->user = $user; |
|
| 89 | + $this->password = $password; |
|
| 90 | + $this->host = $host; |
|
| 91 | + if ($query != '') { |
|
| 92 | + $this->query($query); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * @param $message |
|
| 98 | + * @param string $line |
|
| 99 | + * @param string $file |
|
| 100 | + */ |
|
| 101 | + public function log($message, $line = '', $file = '') |
|
| 102 | + { |
|
| 103 | + error_log($message); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @return int |
|
| 108 | + */ |
|
| 109 | + public function linkId() |
|
| 110 | + { |
|
| 111 | + return $this->linkId; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * @return int |
|
| 116 | + */ |
|
| 117 | + public function queryId() |
|
| 118 | + { |
|
| 119 | + return $this->queryId; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * @param $str |
|
| 124 | + * @return string |
|
| 125 | + */ |
|
| 126 | + public function dbAddslashes($str) |
|
| 127 | + { |
|
| 128 | + if (!isset($str) || $str == '') { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return addslashes($str); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * db:qr() |
|
| 137 | + * |
|
| 138 | + * alias of queryReturn() |
|
| 139 | + * |
|
| 140 | + * @param mixed $query SQL Query to be used |
|
| 141 | + * @param string $line optionally pass __LINE__ calling the query for logging |
|
| 142 | + * @param string $file optionally pass __FILE__ calling the query for logging |
|
| 143 | + * @return mixed FALSE if no rows, if a single row it returns that, if multiple it returns an array of rows, associative responses only |
|
| 144 | + */ |
|
| 145 | + public function qr($query, $line = '', $file = '') |
|
| 146 | + { |
|
| 147 | + return $this->queryReturn($query, $line, $file); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * error handling |
|
| 152 | + * |
|
| 153 | + * @param mixed $msg |
|
| 154 | + * @param string $line |
|
| 155 | + * @param string $file |
|
| 156 | + * @return void |
|
| 157 | + */ |
|
| 158 | + public function halt($msg, $line = '', $file = '') |
|
| 159 | + { |
|
| 160 | + $this->unlock(false); |
|
| 161 | + |
|
| 162 | + if ($this->haltOnError == 'no') { |
|
| 163 | + return; |
|
| 164 | + } |
|
| 165 | + $this->haltmsg($msg); |
|
| 166 | + |
|
| 167 | + if ($file) { |
|
| 168 | + error_log("File: $file"); |
|
| 169 | + } |
|
| 170 | + if ($line) { |
|
| 171 | + error_log("Line: $line"); |
|
| 172 | + } |
|
| 173 | + if ($this->haltOnError != 'report') { |
|
| 174 | + echo '<p><b>Session halted.</b>'; |
|
| 175 | + // FIXME! Add check for error levels |
|
| 176 | + if (isset($GLOBALS['tf'])) { |
|
| 177 | + $GLOBALS['tf']->terminate(); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * @param $msg |
|
| 184 | + */ |
|
| 185 | + public function haltmsg($msg) |
|
| 186 | + { |
|
| 187 | + $this->log("Database error: $msg", __LINE__, __FILE__); |
|
| 188 | + if ($this->Errno != '0' || $this->Error != '()') { |
|
| 189 | + $this->log('SQL Error: '.$this->Errno.' ('.$this->Error.')', __LINE__, __FILE__); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @return array |
|
| 195 | + */ |
|
| 196 | + public function indexNames() |
|
| 197 | + { |
|
| 198 | + return []; |
|
| 199 | + } |
|
| 200 | 200 | } |