[699] | 1 | <?php |
---|
| 2 | /** |
---|
| 3 | * This file is to be used if your codebase still |
---|
| 4 | * uses mysql_* functions in a PHP version that |
---|
| 5 | * doesn't declare those functions (>PHP 5.5.5) |
---|
| 6 | * |
---|
| 7 | * Note: Since this is handled by our object, the DB |
---|
| 8 | * resource link will be the subscript of the database |
---|
| 9 | * connection, 0-X, where X is INT. If not passed, assumed |
---|
| 10 | * subscript last connection. |
---|
| 11 | * |
---|
| 12 | * @author Aziz S. Hussain <azizsaleh@gmail.com> |
---|
| 13 | * @copyright GPL license |
---|
| 14 | * @license http://www.gnu.org/copyleft/gpl.html |
---|
| 15 | * @link http://www.AzizSaleh.com |
---|
| 16 | * @link https://github.com/matthewbaggett/MySQL2PDO |
---|
| 17 | */ |
---|
| 18 | if (!function_exists('mysql_connect') && !defined('MYSQL_ASSOC')) { |
---|
| 19 | |
---|
| 20 | /** |
---|
| 21 | * This file will contain needed definitions for MYSQL |
---|
| 22 | * http://www.php.net/manual/en/mysql.constants.php |
---|
| 23 | * |
---|
| 24 | * @author Aziz S. Hussain <azizsaleh@gmail.com> |
---|
| 25 | * @copyright GPL license |
---|
| 26 | * @license http://www.gnu.org/copyleft/gpl.html |
---|
| 27 | * @link http://www.AzizSaleh.com |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | define('MYSQL_CLIENT_LONG_PASSWORD', 1); |
---|
| 31 | define('MYSQL_CLIENT_FOUND_ROWS', 2); |
---|
| 32 | define('MYSQL_CLIENT_LONG_FLAG', 4); |
---|
| 33 | define('MYSQL_CLIENT_CONNECT_WITH_DB', 8); |
---|
| 34 | define('MYSQL_CLIENT_NO_SCHEMA', 16); |
---|
| 35 | define('MYSQL_CLIENT_COMPRESS', 32); |
---|
| 36 | define('MYSQL_CLIENT_ODBC', 64); |
---|
| 37 | define('MYSQL_CLIENT_LOCAL_FILES', 128); |
---|
| 38 | define('MYSQL_CLIENT_IGNORE_SPACE', 256); |
---|
| 39 | define('MYSQL_CLIENT_PROTOCOL', 512); |
---|
| 40 | define('MYSQL_CLIENT_INTERACTIVE', 1024); |
---|
| 41 | define('MYSQL_CLIENT_SSL', 2048); |
---|
| 42 | define('MYSQL_CLIENT_IGNORE_SIGPIPE', 4096); |
---|
| 43 | define('MYSQL_CLIENT_TRANSACTIONS', 8192); |
---|
| 44 | define('MYSQL_CLIENT_RESERVED', 16384); |
---|
| 45 | define('MYSQL_CLIENT_SECURE_CONNECTION', 32768); |
---|
| 46 | define('MYSQL_CLIENT_MULTI_STATEMENTS', 65535); |
---|
| 47 | define('MYSQL_CLIENT_MULTI_RESULTS', 131072); |
---|
| 48 | define('MYSQL_CLIENT_REMEMBER_OPTIONS', 1 << 31); |
---|
| 49 | |
---|
| 50 | define('MYSQL_ASSOC', 1); |
---|
| 51 | define('MYSQL_NUM', 2); |
---|
| 52 | define('MYSQL_BOTH', 3); |
---|
| 53 | |
---|
| 54 | class MySQL2PDOException extends \Exception |
---|
| 55 | { |
---|
| 56 | |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | /** |
---|
| 60 | * MySQL |
---|
| 61 | * |
---|
| 62 | * This object will replicate MySQL functions |
---|
| 63 | * http://www.php.net/manual/en/ref.mysql.php |
---|
| 64 | * |
---|
| 65 | * @author Aziz S. Hussain <azizsaleh@gmail.com> |
---|
| 66 | * @copyright GPL license |
---|
| 67 | * @license http://www.gnu.org/copyleft/gpl.html |
---|
| 68 | * @link http://www.AzizSaleh.com |
---|
| 69 | */ |
---|
| 70 | class MySQL |
---|
| 71 | { |
---|
| 72 | /** |
---|
| 73 | * Object instance |
---|
| 74 | * |
---|
| 75 | * @var MySQL |
---|
| 76 | */ |
---|
| 77 | protected static $_instance; |
---|
| 78 | |
---|
| 79 | /** |
---|
| 80 | * Instances of the Db |
---|
| 81 | * |
---|
| 82 | * Start position @ 1 |
---|
| 83 | * |
---|
| 84 | * @array PDO |
---|
| 85 | */ |
---|
| 86 | protected $_instances = array(array()); |
---|
| 87 | |
---|
| 88 | /** |
---|
| 89 | * Db Instances params |
---|
| 90 | * |
---|
| 91 | * @var array |
---|
| 92 | */ |
---|
| 93 | protected $_params = array(); |
---|
| 94 | |
---|
| 95 | /** |
---|
| 96 | * Next offset used by mysql_field_seek |
---|
| 97 | * |
---|
| 98 | * @var int |
---|
| 99 | */ |
---|
| 100 | protected $_nextOffset = false; |
---|
| 101 | |
---|
| 102 | /** |
---|
| 103 | * Row seek |
---|
| 104 | * |
---|
| 105 | * @var int |
---|
| 106 | */ |
---|
| 107 | protected $_rowSeek = array(); |
---|
| 108 | |
---|
| 109 | /** |
---|
| 110 | * Get singelton instance |
---|
| 111 | * |
---|
| 112 | * @return MySQL |
---|
| 113 | */ |
---|
| 114 | public static function getInstance() |
---|
| 115 | { |
---|
| 116 | if (!isset(self::$_instance)) { |
---|
| 117 | self::$_instance = new self(); |
---|
| 118 | } |
---|
| 119 | return self::$_instance; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | public function mysql_add_existing_connection($dbh) |
---|
| 123 | { |
---|
| 124 | $usePosition = count($this->_instances) + 1; |
---|
| 125 | |
---|
| 126 | // Set connection params |
---|
| 127 | $this->_params[$usePosition] = array ( |
---|
| 128 | 'server' => '', |
---|
| 129 | 'username' => '', |
---|
| 130 | 'password' => '', |
---|
| 131 | 'newLink' => true, |
---|
| 132 | 'clientFlags' => array(), |
---|
| 133 | 'errno' => 0, |
---|
| 134 | 'error' => "", |
---|
| 135 | 'rowCount' => -1, |
---|
| 136 | 'lastQuery' => false, |
---|
| 137 | ); |
---|
| 138 | |
---|
| 139 | $this->_instances[$usePosition] = $dbh; |
---|
| 140 | return true; |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | * mysql_connect |
---|
| 145 | * http://www.php.net/manual/en/function.mysql-connect.php |
---|
| 146 | */ |
---|
| 147 | public function mysql_connect($server, $username, $password, $newLink = false, $clientFlags = false, $usePosition = false) |
---|
| 148 | { |
---|
| 149 | // If we don't have to create a new instance and we have an instance, return it |
---|
| 150 | if ($newLink == false && count($this->_instances) > 1) { |
---|
| 151 | return count($this->_instances); |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | $flags = $this->_translateFlags($clientFlags); |
---|
| 155 | |
---|
| 156 | // Set connection element |
---|
| 157 | if ($usePosition === false) { |
---|
| 158 | $usePosition = count($this->_instances) + 1; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | // Set connection params |
---|
| 162 | $this->_params[$usePosition] = array ( |
---|
| 163 | 'server' => $server, |
---|
| 164 | 'username' => $username, |
---|
| 165 | 'password' => $password, |
---|
| 166 | 'newLink' => $newLink, |
---|
| 167 | 'clientFlags' => $clientFlags, |
---|
| 168 | 'errno' => 0, |
---|
| 169 | 'error' => "", |
---|
| 170 | 'rowCount' => -1, |
---|
| 171 | 'lastQuery' => false, |
---|
| 172 | ); |
---|
| 173 | |
---|
| 174 | // Create new instance |
---|
| 175 | $dsn = "mysql:host={$server}"; |
---|
| 176 | try { |
---|
| 177 | // Add instance |
---|
[719] | 178 | $this->_instances[$usePosition] = new PDO($dsn, $username, $password, $flags); |
---|
[699] | 179 | |
---|
| 180 | return $usePosition; |
---|
| 181 | } catch (PDOException $e) { |
---|
| 182 | // Mock the instance for error reporting |
---|
| 183 | $this->_instances[$usePosition] = array(); |
---|
| 184 | $this->_loadError($usePosition, $e); |
---|
| 185 | return false; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | return false; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | /** |
---|
| 192 | * mysql_pconnect |
---|
| 193 | * http://www.php.net/manual/en/function.mysql-pconnect.php |
---|
| 194 | */ |
---|
| 195 | public function mysql_pconnect($server, $username, $password, $newLink = false, $clientFlags = false) |
---|
| 196 | { |
---|
| 197 | $persistent = PDO::ATTR_PERSISTENT; |
---|
| 198 | $clientFlags = ($clientFlags !== false) ? array_merge($clientFlags, $persistent) : $persistent; |
---|
| 199 | return $this->mysql_connect($server, $username, $password, $newLink, $clientFlags); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | /** |
---|
| 203 | * mysql_select_db |
---|
| 204 | * http://www.php.net/manual/en/function.mysql-select-db.php |
---|
| 205 | */ |
---|
| 206 | public function mysql_select_db($databaseName, $link = false) |
---|
| 207 | { |
---|
| 208 | $link = $this->_getLastLink($link); |
---|
| 209 | |
---|
| 210 | // Select the DB |
---|
| 211 | try { |
---|
| 212 | $this->_params[$link]['databaseName'] = $databaseName; |
---|
[716] | 213 | return $this->mysql_query("USE `{$databaseName}`", $link); |
---|
[699] | 214 | } catch (PDOException $e) { |
---|
| 215 | return false; |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | return false; |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | /** |
---|
| 222 | * mysql_query |
---|
| 223 | * http://www.php.net/manual/en/function.mysql-query.php |
---|
| 224 | */ |
---|
| 225 | public function mysql_query($query, $link = false) |
---|
| 226 | { |
---|
| 227 | $link = $this->_getLastLink($link); |
---|
| 228 | |
---|
| 229 | try { |
---|
| 230 | if ($res = $this->_instances[$link]->query($query)) { |
---|
| 231 | $this->_params[$link]['rowCount'] = $res->rowCount(); |
---|
| 232 | $this->_params[$link]['lastQuery'] = $res; |
---|
| 233 | $this->_loadError($link, false); |
---|
| 234 | return $res; |
---|
| 235 | } |
---|
| 236 | } catch (PDOException $e) { |
---|
| 237 | $this->_loadError($link, $e); |
---|
| 238 | } |
---|
| 239 | |
---|
| 240 | $this->_params[$link]['rowCount'] = -1; |
---|
| 241 | $this->_params[$link]['lastQuery'] = false; |
---|
| 242 | |
---|
| 243 | // Set query error |
---|
| 244 | $errorCode = $this->_instances[$link]->errorInfo(); |
---|
| 245 | $this->_params[$link]['errno'] = $errorCode[1]; |
---|
| 246 | $this->_params[$link]['error'] = $errorCode[2]; |
---|
| 247 | return false; |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | /** |
---|
| 251 | * mysql_unbuffered_query |
---|
| 252 | * http://www.php.net/manual/en/function.mysql-unbuffered-query.php |
---|
| 253 | */ |
---|
| 254 | public function mysql_unbuffered_query($query, $link = false) |
---|
| 255 | { |
---|
| 256 | return $this->mysql_query($query, $link); |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | /** |
---|
| 260 | * mysql_fetch_array |
---|
| 261 | * http://www.php.net/manual/en/function.mysql-fetch-array.php |
---|
| 262 | */ |
---|
| 263 | public function mysql_fetch_array(&$result, $resultType = 3, $doCounts = false, $elementId = false) |
---|
| 264 | { |
---|
| 265 | static $last = null; |
---|
| 266 | |
---|
[756] | 267 | if ($result === false || $result === null) { |
---|
[699] | 268 | trigger_error('mysql_fetch_*(): supplied argument is not a valid MySQL result resource', E_USER_WARNING); |
---|
| 269 | return false; |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | // Are we only doing length counts? |
---|
| 273 | if ($doCounts === true) { |
---|
| 274 | return $this->_mysqlGetLengths($last, $elementId); |
---|
| 275 | } |
---|
| 276 | |
---|
| 277 | $hash = false; |
---|
| 278 | |
---|
| 279 | // Set retrieval type |
---|
| 280 | if (!is_array($result)) { |
---|
| 281 | $hash = spl_object_hash($result); |
---|
| 282 | switch ($resultType) { |
---|
| 283 | case 1: |
---|
| 284 | // by field names only as array |
---|
| 285 | $result = $result->fetchAll(PDO::FETCH_ASSOC); |
---|
| 286 | break; |
---|
| 287 | case 2: |
---|
| 288 | // by field position only as array |
---|
| 289 | $result = $result->fetchAll(PDO::FETCH_NUM); |
---|
| 290 | break; |
---|
| 291 | case 3: |
---|
| 292 | // by both field name/position as array |
---|
| 293 | $result = $result->fetchAll(); |
---|
| 294 | break; |
---|
| 295 | case 4: |
---|
| 296 | // by field names as object |
---|
| 297 | $result = $result->fetchAll(PDO::FETCH_OBJ); |
---|
| 298 | break; |
---|
| 299 | } |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | // Row seek |
---|
| 303 | if ($hash !== false && isset($this->_rowSeek[$hash])) { |
---|
| 304 | // Check valid skip |
---|
| 305 | $rowNumber = $this->_rowSeek[$hash]; |
---|
| 306 | if ($rowNumber > count($result) - 1) { |
---|
| 307 | trigger_error("mysql_data_seek(): Offset $rowNumber is invalid for MySQL result (or the query data is unbuffered)", E_USER_WARNING); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | while ($rowNumber > 0) { |
---|
| 311 | next($result); |
---|
| 312 | $rowNumber--; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | unset($this->_rowSeek[$hash]); |
---|
| 316 | } |
---|
| 317 | |
---|
| 318 | $last = current($result); |
---|
| 319 | next($result); |
---|
| 320 | |
---|
| 321 | return $last; |
---|
| 322 | } |
---|
| 323 | |
---|
| 324 | /** |
---|
| 325 | * mysql_fetch_assoc |
---|
| 326 | * http://www.php.net/manual/en/function.mysql-fetch-assoc.php |
---|
| 327 | */ |
---|
| 328 | public function mysql_fetch_assoc(&$result) |
---|
| 329 | { |
---|
| 330 | return $this->mysql_fetch_array($result, 1); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | /** |
---|
| 334 | * mysql_fetch_row |
---|
| 335 | * http://www.php.net/manual/en/function.mysql-fetch-row.php |
---|
| 336 | */ |
---|
| 337 | public function mysql_fetch_row(&$result) |
---|
| 338 | { |
---|
| 339 | return $this->mysql_fetch_array($result, 2); |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | /** |
---|
| 343 | * mysql_fetch_object |
---|
| 344 | * http://www.php.net/manual/en/function.mysql-fetch-object.php |
---|
| 345 | */ |
---|
| 346 | public function mysql_fetch_object(&$result) |
---|
| 347 | { |
---|
| 348 | return $this->mysql_fetch_array($result, 4); |
---|
| 349 | } |
---|
| 350 | |
---|
| 351 | /** |
---|
| 352 | * mysql_num_fields |
---|
| 353 | * http://www.php.net/manual/en/function.mysql-num-fields.php |
---|
| 354 | */ |
---|
| 355 | public function mysql_num_fields($result) |
---|
| 356 | { |
---|
| 357 | if (is_array($result)) { |
---|
| 358 | return count($result); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | $data = $result->fetch(PDO::FETCH_NUM); |
---|
| 362 | return count($data); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /** |
---|
| 366 | * mysql_num_rows |
---|
| 367 | * http://www.php.net/manual/en/function.mysql-num-rows.php |
---|
| 368 | */ |
---|
| 369 | public function mysql_num_rows($result) |
---|
| 370 | { |
---|
| 371 | if (is_array($result)) { |
---|
| 372 | return count($result); |
---|
| 373 | } |
---|
| 374 | |
---|
| 375 | // Hard clone (cloning PDOStatements doesn't work) |
---|
| 376 | $query = $result->queryString; |
---|
| 377 | $cloned = $this->mysql_query($query); |
---|
| 378 | if ($cloned) { |
---|
| 379 | $data = $cloned->fetchAll(); |
---|
| 380 | return count($data); |
---|
| 381 | } else { |
---|
| 382 | return false; |
---|
| 383 | } |
---|
| 384 | } |
---|
| 385 | |
---|
| 386 | /** |
---|
| 387 | * mysql_ping |
---|
| 388 | * http://www.php.net/manual/en/function.mysql-ping.php |
---|
| 389 | */ |
---|
| 390 | public function mysql_ping($link = false) |
---|
| 391 | { |
---|
| 392 | $link = $this->_getLastLink($link); |
---|
| 393 | |
---|
| 394 | try { |
---|
| 395 | $this->_instances[$link]->query('SELECT 1'); |
---|
| 396 | $this->_loadError($link, false); |
---|
| 397 | } catch (PDOException $e) { |
---|
| 398 | try { |
---|
| 399 | // Reconnect |
---|
| 400 | $set = $this->mysql_connect( |
---|
| 401 | $this->_params[$link]['server'], |
---|
| 402 | $this->_params[$link]['username'], |
---|
| 403 | $this->_params[$link]['password'], |
---|
| 404 | $this->_params[$link]['newLink'], |
---|
| 405 | $this->_params[$link]['clientFlags'], |
---|
| 406 | $link |
---|
| 407 | ); |
---|
| 408 | } catch (PDOException $e) { |
---|
| 409 | $this->_loadError($link, $e); |
---|
| 410 | return false; |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | // Select db if any |
---|
| 414 | if (isset($this->_params[$link]['databaseName'])) { |
---|
| 415 | $set = $this->mysql_select_db($this->_params[$link]['databaseName'], $link); |
---|
| 416 | |
---|
| 417 | if (!$set) { |
---|
| 418 | return false; |
---|
| 419 | } |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | |
---|
| 423 | return true; |
---|
| 424 | } |
---|
| 425 | |
---|
| 426 | /** |
---|
| 427 | * mysql_affected_rows |
---|
| 428 | * http://www.php.net/manual/en/function.mysql-affected-rows.php |
---|
| 429 | */ |
---|
| 430 | public function mysql_affected_rows($link = false) |
---|
| 431 | { |
---|
| 432 | $link = $this->_getLastLink($link); |
---|
| 433 | |
---|
| 434 | return $this->_params[$link]['rowCount']; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | /** |
---|
| 438 | * mysql_client_encoding |
---|
| 439 | * http://www.php.net/manual/en/function.mysql-client-encoding.php |
---|
| 440 | */ |
---|
| 441 | public function mysql_client_encoding($link = false) |
---|
| 442 | { |
---|
| 443 | $link = $this->_getLastLink($link); |
---|
| 444 | |
---|
| 445 | $res = $this->_instances[$link]->query('SELECT @@character_set_database')->fetch(PDO::FETCH_NUM); |
---|
| 446 | |
---|
| 447 | return $res[0]; |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | /** |
---|
| 451 | * mysql_close |
---|
| 452 | * http://www.php.net/manual/en/function.mysql-close.php |
---|
| 453 | */ |
---|
| 454 | public function mysql_close($link = false) |
---|
| 455 | { |
---|
| 456 | $link = $this->_getLastLink($link); |
---|
| 457 | |
---|
| 458 | if (isset($this->_instances[$link])) { |
---|
| 459 | $this->_instances[$link] = null; |
---|
| 460 | unset($this->_instances[$link]); |
---|
| 461 | return true; |
---|
| 462 | } |
---|
| 463 | |
---|
| 464 | return false; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | /** |
---|
| 468 | * mysql_create_db |
---|
| 469 | * http://www.php.net/manual/en/function.mysql-create-db.php |
---|
| 470 | */ |
---|
| 471 | public function mysql_create_db($databaseName, $link = false) |
---|
| 472 | { |
---|
| 473 | $link = $this->_getLastLink($link); |
---|
| 474 | return $this->_instances[$link]->prepare('CREATE DATABASE ' . $databaseName)->execute(); |
---|
| 475 | } |
---|
| 476 | |
---|
| 477 | /** |
---|
| 478 | * mysql_data_seek |
---|
| 479 | * http://www.php.net/manual/en/function.mysql-data-seek.php |
---|
| 480 | */ |
---|
| 481 | public function mysql_data_seek($result, $rowNumber) |
---|
| 482 | { |
---|
| 483 | // Set seek |
---|
| 484 | $this->_rowSeek[spl_object_hash($result)] = $rowNumber; |
---|
| 485 | return true; |
---|
| 486 | } |
---|
| 487 | |
---|
| 488 | /** |
---|
| 489 | * mysql_list_dbs |
---|
| 490 | * http://www.php.net/manual/en/function.mysql-list-dbs.php |
---|
| 491 | */ |
---|
| 492 | public function mysql_list_dbs($link = false) |
---|
| 493 | { |
---|
| 494 | $link = $this->_getLastLink($link); |
---|
| 495 | |
---|
| 496 | return $this->_instances[$link]->query('SHOW DATABASES'); |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | /** |
---|
| 500 | * mysql_db_name |
---|
| 501 | * http://www.php.net/manual/en/function.mysql-db-name.php |
---|
| 502 | */ |
---|
| 503 | public function mysql_db_name(&$result, $row, $field = 'Database') |
---|
| 504 | { |
---|
| 505 | // Get list if not gotten yet (still PDOStatement) |
---|
| 506 | if (!is_array($result)) { |
---|
| 507 | $result = $result->fetchAll(PDO::FETCH_ASSOC); |
---|
| 508 | } |
---|
| 509 | |
---|
| 510 | if (isset($result[$row][$field])) { |
---|
| 511 | return $result[$row][$field]; |
---|
| 512 | } |
---|
| 513 | |
---|
| 514 | return ''; |
---|
| 515 | } |
---|
| 516 | |
---|
| 517 | /** |
---|
| 518 | * mysql_db_query |
---|
| 519 | * http://www.php.net/manual/en/function.mysql-db-query.php |
---|
| 520 | */ |
---|
| 521 | public function mysql_db_query($databaseName, $query, $link = false) |
---|
| 522 | { |
---|
| 523 | $link = $this->_getLastLink($link); |
---|
| 524 | |
---|
| 525 | $this->mysql_select_db($databaseName, $link); |
---|
| 526 | |
---|
| 527 | return $this->mysql_query($query, $link); |
---|
| 528 | } |
---|
| 529 | |
---|
| 530 | /** |
---|
| 531 | * mysql_drop_db |
---|
| 532 | * http://www.php.net/manual/en/function.mysql-drop-db.php |
---|
| 533 | */ |
---|
| 534 | public function mysql_drop_db($databaseName, $link = false) |
---|
| 535 | { |
---|
| 536 | $link = $this->_getLastLink($link); |
---|
| 537 | |
---|
| 538 | return $this->_instances[$link]->prepare('DROP DATABASE ' . $databaseName)->execute(); |
---|
| 539 | } |
---|
| 540 | |
---|
| 541 | /** |
---|
| 542 | * mysql_thread_id |
---|
| 543 | * http://www.php.net/manual/en/function.mysql-thread-id.php |
---|
| 544 | */ |
---|
| 545 | public function mysql_thread_id($link = false) |
---|
| 546 | { |
---|
| 547 | $link = $this->_getLastLink($link); |
---|
| 548 | |
---|
| 549 | $res = $this->_instances[$link] |
---|
| 550 | ->query('SELECT CONNECTION_ID()')->fetch(PDO::FETCH_NUM); |
---|
| 551 | |
---|
| 552 | return $res[0]; |
---|
| 553 | } |
---|
| 554 | |
---|
| 555 | /** |
---|
| 556 | * mysql_list_tables |
---|
| 557 | * http://www.php.net/manual/en/function.mysql-list-tables.php |
---|
| 558 | */ |
---|
| 559 | public function mysql_list_tables($databaseName, $link = false) |
---|
| 560 | { |
---|
| 561 | $link = $this->_getLastLink($link); |
---|
| 562 | |
---|
| 563 | return $this->_instances[$link]->query('SHOW TABLES FROM ' . $databaseName); |
---|
| 564 | } |
---|
| 565 | |
---|
| 566 | /** |
---|
| 567 | * mysql_tablename |
---|
| 568 | * http://www.php.net/manual/en/function.mysql-tablename.php |
---|
| 569 | */ |
---|
| 570 | public function mysql_tablename(&$result, $row) |
---|
| 571 | { |
---|
| 572 | // Get list if not gotten yet (still PDOStatement) |
---|
| 573 | if (!is_array($result)) { |
---|
| 574 | $result = $result->fetchAll(PDO::FETCH_NUM); |
---|
| 575 | } |
---|
| 576 | |
---|
| 577 | $counter = count($result); |
---|
| 578 | for ($x = 0; $x < $counter; $x++) { |
---|
| 579 | if ($x == $row) { |
---|
| 580 | return $result[$row][0]; |
---|
| 581 | } |
---|
| 582 | } |
---|
| 583 | |
---|
| 584 | return ''; |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | /** |
---|
| 588 | * mysql_fetch_lengths |
---|
| 589 | * http://www.php.net/manual/en/function.mysql-fetch-lengths.php |
---|
| 590 | */ |
---|
| 591 | public function mysql_fetch_lengths(&$result) |
---|
| 592 | { |
---|
| 593 | // Get list if not gotten yet (still PDOStatement) |
---|
| 594 | return $this->mysql_fetch_array($result, false, true); |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | /** |
---|
| 598 | * mysql_field_len |
---|
| 599 | * http://www.php.net/manual/en/function.mysql-field-len.php |
---|
| 600 | */ |
---|
| 601 | public function mysql_field_len(&$result, $fieldOffset = false) |
---|
| 602 | { |
---|
| 603 | if (!is_array($result)) { |
---|
| 604 | $result = $result->fetchAll(PDO::FETCH_NUM); |
---|
| 605 | $result = current($result); |
---|
| 606 | } |
---|
| 607 | |
---|
| 608 | return $this->_mysqlGetLengths($result, $fieldOffset); |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | /** |
---|
| 612 | * mysql_field_flags |
---|
| 613 | * http://www.php.net/manual/en/function.mysql-field-flags.php |
---|
| 614 | */ |
---|
| 615 | public function mysql_field_flags(&$result, $fieldOffset = false) |
---|
| 616 | { |
---|
| 617 | return $this->_getColumnMeta($result, 'flags', $fieldOffset); |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | /** |
---|
| 621 | * mysql_field_name |
---|
| 622 | * http://www.php.net/manual/en/function.mysql-field-name.php |
---|
| 623 | */ |
---|
| 624 | public function mysql_field_name(&$result, $fieldOffset = false) |
---|
| 625 | { |
---|
| 626 | return $this->_getColumnMeta($result, 'name', $fieldOffset); |
---|
| 627 | } |
---|
| 628 | |
---|
| 629 | /** |
---|
| 630 | * mysql_field_type |
---|
| 631 | * http://www.php.net/manual/en/function.mysql-field-type.php |
---|
| 632 | */ |
---|
| 633 | public function mysql_field_type(&$result, $fieldOffset = false) |
---|
| 634 | { |
---|
| 635 | return $this->_getColumnMeta($result, 'type', $fieldOffset); |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | /** |
---|
| 639 | * mysql_field_table |
---|
| 640 | * http://www.php.net/manual/en/function.mysql-field-table.php |
---|
| 641 | */ |
---|
| 642 | public function mysql_field_table(&$result, $fieldOffset = false) |
---|
| 643 | { |
---|
| 644 | return $this->_getColumnMeta($result, 'table', $fieldOffset); |
---|
| 645 | } |
---|
| 646 | /** |
---|
| 647 | * mysql_fetch_field |
---|
| 648 | * http://www.php.net/manual/en/function.mysql-fetch-field.php |
---|
| 649 | */ |
---|
| 650 | public function mysql_fetch_field(&$result, $fieldOffset = false) |
---|
| 651 | { |
---|
| 652 | return $this->_getColumnMeta($result, false, $fieldOffset); |
---|
| 653 | } |
---|
| 654 | |
---|
| 655 | /** |
---|
| 656 | * mysql_field_seek |
---|
| 657 | * http://www.php.net/manual/en/function.mysql-field-seek.php |
---|
| 658 | */ |
---|
| 659 | public function mysql_field_seek(&$result, $fieldOffset = false) |
---|
| 660 | { |
---|
| 661 | $this->_nextOffset = $fieldOffset; |
---|
| 662 | } |
---|
| 663 | |
---|
| 664 | /** |
---|
| 665 | * mysql_stat |
---|
| 666 | * http://www.php.net/manual/en/function.mysql-stat.php |
---|
| 667 | */ |
---|
| 668 | public function mysql_stat($link = false) |
---|
| 669 | { |
---|
| 670 | $link = $this->_getLastLink($link); |
---|
| 671 | return $this->_instances[$link]->getAttribute(PDO::ATTR_SERVER_INFO); |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | /** |
---|
| 675 | * mysql_get_server_info |
---|
| 676 | * http://www.php.net/manual/en/function.mysql-get-server-info.php |
---|
| 677 | */ |
---|
| 678 | public function mysql_get_server_info($link = false) |
---|
| 679 | { |
---|
| 680 | $link = $this->_getLastLink($link); |
---|
| 681 | return $this->_instances[$link]->getAttribute(PDO::ATTR_SERVER_VERSION); |
---|
| 682 | } |
---|
| 683 | |
---|
| 684 | /** |
---|
| 685 | * mysql_get_proto_info |
---|
| 686 | * http://www.php.net/manual/en/function.mysql-get-proto-info.php |
---|
| 687 | */ |
---|
| 688 | public function mysql_get_proto_info($link = false) |
---|
| 689 | { |
---|
| 690 | $link = $this->_getLastLink($link); |
---|
| 691 | |
---|
| 692 | $res = $this->_instances[$link] |
---|
| 693 | ->query("SHOW VARIABLES LIKE 'protocol_version'")->fetch(PDO::FETCH_NUM); |
---|
| 694 | |
---|
| 695 | return (int) $res[1]; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | /** |
---|
| 699 | * mysql_get_host_info |
---|
| 700 | * http://www.php.net/manual/en/function.mysql-get-server-info.php |
---|
| 701 | */ |
---|
| 702 | public function mysql_get_host_info($link = false) |
---|
| 703 | { |
---|
| 704 | $link = $this->_getLastLink($link); |
---|
| 705 | return $this->_instances[$link]->getAttribute(PDO::ATTR_CONNECTION_STATUS); |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | /** |
---|
| 709 | * mysql_get_client_info |
---|
| 710 | * http://www.php.net/manual/en/function.mysql-get-client-info.php |
---|
| 711 | */ |
---|
| 712 | public function mysql_get_client_info($link = false) |
---|
| 713 | { |
---|
| 714 | $link = $this->_getLastLink($link); |
---|
| 715 | return $this->_instances[$link]->getAttribute(PDO::ATTR_CLIENT_VERSION); |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | /** |
---|
| 719 | * mysql_free_result |
---|
| 720 | * http://www.php.net/manual/en/function.mysql-free-result.php |
---|
| 721 | */ |
---|
| 722 | public function mysql_free_result(&$result) |
---|
| 723 | { |
---|
| 724 | if (is_array($result)) { |
---|
| 725 | $result = false; |
---|
| 726 | return true; |
---|
| 727 | } |
---|
| 728 | |
---|
| 729 | if (get_class($result) != 'PDOStatement') { |
---|
| 730 | return false; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | return $result->closeCursor(); |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | /** |
---|
| 737 | * mysql_result |
---|
| 738 | * http://www.php.net/manual/en/function.mysql-result.php |
---|
| 739 | */ |
---|
| 740 | public function mysql_result(&$result, $row, $field = false) |
---|
| 741 | { |
---|
| 742 | |
---|
| 743 | // Get list if not gotten yet (still PDOStatement) |
---|
| 744 | if (!is_array($result)) { |
---|
| 745 | $result = $result->fetchAll(PDO::FETCH_ASSOC); |
---|
| 746 | } |
---|
| 747 | |
---|
| 748 | $counter = count($result); |
---|
| 749 | for ($x = 0; $x < $counter; $x++) { |
---|
| 750 | if ($x == $row) { |
---|
| 751 | if ($field === false) { |
---|
| 752 | return current($result[$row]); |
---|
| 753 | } else { |
---|
| 754 | return $result[$row][$field]; |
---|
| 755 | } |
---|
| 756 | } |
---|
| 757 | } |
---|
| 758 | |
---|
| 759 | return ''; |
---|
| 760 | } |
---|
| 761 | |
---|
| 762 | /** |
---|
| 763 | * mysql_list_processes |
---|
| 764 | * http://www.php.net/manual/en/function.mysql-list-processes.php |
---|
| 765 | */ |
---|
| 766 | public function mysql_list_processes($link = false) |
---|
| 767 | { |
---|
| 768 | $link = $this->_getLastLink($link); |
---|
| 769 | return $this->_instances[$link]->query("SHOW PROCESSLIST"); |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | /** |
---|
| 773 | * mysql_set_charset |
---|
| 774 | * http://www.php.net/manual/en/function.mysql-set-charset.php |
---|
| 775 | */ |
---|
| 776 | public function mysql_set_charset($charset, $link = false) |
---|
| 777 | { |
---|
| 778 | $link = $this->_getLastLink($link); |
---|
| 779 | $set = "SET character_set_results = '$charset', character_set_client = '$charset', character_set_connection = '$charset', character_set_database = '$charset', character_set_server = '$charset'"; |
---|
| 780 | return $this->_instances[$link]->query($set); |
---|
| 781 | } |
---|
| 782 | |
---|
| 783 | /** |
---|
| 784 | * mysql_insert_id |
---|
| 785 | * http://www.php.net/manual/en/function.mysql-insert-id.php |
---|
| 786 | */ |
---|
| 787 | public function mysql_insert_id($link = false) |
---|
| 788 | { |
---|
| 789 | if(!$link instanceof PDOStatement) { |
---|
| 790 | $link = $this->_getLastLink($link); |
---|
| 791 | $resource = $this->_instances[$link]; |
---|
| 792 | }else{ |
---|
| 793 | $resource = $link; |
---|
| 794 | } |
---|
| 795 | |
---|
| 796 | return $resource->lastInsertId(); |
---|
| 797 | } |
---|
| 798 | |
---|
| 799 | /** |
---|
| 800 | * mysql_list_fields |
---|
| 801 | * http://www.php.net/manual/en/function.mysql-list-fields.php |
---|
| 802 | */ |
---|
| 803 | public function mysql_list_fields($databaseName, $tableName, $link = false) |
---|
| 804 | { |
---|
| 805 | $link = $this->_getLastLink($link); |
---|
| 806 | return $this->_instances[$link]->query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '$databaseName' AND TABLE_NAME = '$tableName'")->fetchAll(); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | /** |
---|
| 810 | * mysql_errno |
---|
| 811 | * http://www.php.net/manual/en/function.mysql-errno.php |
---|
| 812 | */ |
---|
| 813 | public function mysql_errno($link = false) |
---|
| 814 | { |
---|
| 815 | $link = $this->_getLastLink($link, false); |
---|
| 816 | return $this->_params[$link]['errno']; |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | /** |
---|
| 820 | * mysql_error |
---|
| 821 | * http://www.php.net/manual/en/function.mysql-error.php |
---|
| 822 | */ |
---|
| 823 | public function mysql_error($link = false) |
---|
| 824 | { |
---|
| 825 | $link = $this->_getLastLink($link, false); |
---|
| 826 | return $this->_params[$link]['error']; |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | /** |
---|
| 830 | * mysql_real_escape_string |
---|
| 831 | * http://www.php.net/manual/en/function.mysql-real-escape-string.php |
---|
| 832 | */ |
---|
| 833 | public function mysql_real_escape_string($string, $link = false) |
---|
| 834 | { |
---|
| 835 | $link = $this->_getLastLink($link); |
---|
| 836 | |
---|
| 837 | try { |
---|
| 838 | $string = $this->_instances[$link]->quote($string); |
---|
| 839 | $this->_loadError($link, false); |
---|
| 840 | return substr($string, 1, -1); |
---|
| 841 | } catch (PDOException $e) { |
---|
| 842 | $this->_loadError($link, $e); |
---|
| 843 | return false; |
---|
| 844 | } |
---|
| 845 | |
---|
| 846 | return false; |
---|
| 847 | } |
---|
| 848 | |
---|
| 849 | /** |
---|
| 850 | * mysql_escape_string |
---|
| 851 | * http://www.php.net/manual/en/function.mysql-escape-string.php |
---|
| 852 | */ |
---|
| 853 | public function mysql_escape_string($string, $link = false) |
---|
| 854 | { |
---|
| 855 | $link = $this->_getLastLink($link, false); |
---|
| 856 | return $this->mysql_real_escape_string($string, $link); |
---|
| 857 | } |
---|
| 858 | |
---|
| 859 | /** |
---|
| 860 | * mysql_info |
---|
| 861 | * |
---|
| 862 | * Not sure how to get the actual result message from MySQL |
---|
| 863 | * so the best I could do was to get the affected rows |
---|
| 864 | * and construct a message that way. If you have a better way |
---|
| 865 | * or know of a more accurate method, send it to me @ |
---|
| 866 | * azizsaleh@gmail.com and I'll update the code with it. All I got is |
---|
| 867 | * the affected rows, so it will be missing changed, warnings, |
---|
| 868 | * skipped, and rows matched |
---|
| 869 | * |
---|
| 870 | * http://www.php.net/manual/en/function.mysql-escape-string.php |
---|
| 871 | */ |
---|
| 872 | public function mysql_info($link = false) |
---|
| 873 | { |
---|
| 874 | $link = $this->_getLastLink($link); |
---|
| 875 | |
---|
| 876 | $query = $this->_params[$link]['lastQuery']; |
---|
| 877 | |
---|
| 878 | if (!isset($query->queryString)) { |
---|
| 879 | return false; |
---|
| 880 | } |
---|
| 881 | |
---|
| 882 | $affected = $this->_params[$link]['rowCount']; |
---|
| 883 | |
---|
| 884 | if (strtoupper(substr($query->queryString, 0, 5)) == 'INSERT INTO') { |
---|
| 885 | return "Records: {$affected} Duplicates: 0 Warnings: 0"; |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | if (strtoupper(substr($query->queryString, 0, 9)) == 'LOAD DATA') { |
---|
| 889 | return "Records: {$affected} Deleted: 0 Skipped: 0 Warnings: 0"; |
---|
| 890 | } |
---|
| 891 | |
---|
| 892 | if (strtoupper(substr($query->queryString, 0, 11)) == 'ALTER TABLE') { |
---|
| 893 | return "Records: {$affected} Duplicates: 0 Warnings: 0"; |
---|
| 894 | } |
---|
| 895 | |
---|
| 896 | if (strtoupper(substr($query->queryString, 0, 6)) == 'UPDATE') { |
---|
| 897 | return "Rows matched: {$affected} Changed: {$affected} Warnings: 0"; |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | if (strtoupper(substr($query->queryString, 0, 6)) == 'DELETE') { |
---|
| 901 | return "Records: 0 Deleted: {$affected} Skipped: 0 Warnings: 0"; |
---|
| 902 | } |
---|
| 903 | |
---|
| 904 | return false; |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | /** |
---|
| 908 | * Close all connections |
---|
| 909 | * |
---|
| 910 | * @return void |
---|
| 911 | */ |
---|
| 912 | public function mysql_close_all() |
---|
| 913 | { |
---|
| 914 | // Free connections |
---|
| 915 | foreach ($this->_instances as $id => $pdo) { |
---|
| 916 | $this->_instances[$id] = null; |
---|
| 917 | } |
---|
| 918 | |
---|
| 919 | // Reset arrays |
---|
| 920 | $this->_instances = array(array()); |
---|
| 921 | $this->_params = array(); |
---|
| 922 | } |
---|
| 923 | |
---|
| 924 | /** |
---|
| 925 | * is_resource function over ride |
---|
| 926 | * |
---|
| 927 | * @param RESOURCE $resource |
---|
| 928 | * |
---|
| 929 | * @return boolean |
---|
| 930 | */ |
---|
| 931 | public function is_resource($resource) |
---|
| 932 | { |
---|
| 933 | // Check for a mysql result |
---|
| 934 | if (is_object($resource) && $resource instanceof PDOStatement) { |
---|
| 935 | return true; |
---|
| 936 | // Check if it is a mysql instance |
---|
| 937 | } elseif (isset($this->_instances[$resource]) && !empty($this->_instances[$resource])) { |
---|
| 938 | return true; |
---|
| 939 | } |
---|
| 940 | |
---|
| 941 | return is_resource($resource); |
---|
| 942 | } |
---|
| 943 | |
---|
| 944 | /** |
---|
| 945 | * get_resource_type function over ride |
---|
| 946 | * |
---|
| 947 | * @param RESOURCE $resource |
---|
| 948 | * |
---|
| 949 | * @return boolean |
---|
| 950 | */ |
---|
| 951 | public function get_resource_type($resource) |
---|
| 952 | { |
---|
| 953 | // mysql result resource type |
---|
| 954 | if (is_object($resource) && $resource instanceof PDOStatement) { |
---|
| 955 | return 'mysql result'; |
---|
| 956 | } |
---|
| 957 | |
---|
| 958 | // Check if it is a mysql instance |
---|
| 959 | if (isset($this->_instances[$resource]) && !empty($this->_instances[$resource])) { |
---|
| 960 | // Check type |
---|
| 961 | if ($this->_params[$resource]['clientFlags'] == PDO::ATTR_PERSISTENT) { |
---|
| 962 | return 'mysql link persistent'; |
---|
| 963 | } else { |
---|
| 964 | return 'mysql link'; |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | |
---|
| 968 | return get_resource_type($resource); |
---|
| 969 | } |
---|
| 970 | |
---|
| 971 | /** |
---|
| 972 | * Get column meta information |
---|
| 973 | * |
---|
| 974 | * @param object $result |
---|
| 975 | * @param enum|boolean $type flags|name|type|table|len |
---|
| 976 | * @param int $index |
---|
| 977 | * |
---|
| 978 | * @return mixed |
---|
| 979 | */ |
---|
| 980 | protected function _getColumnMeta(&$result, $type, $index) |
---|
| 981 | { |
---|
| 982 | // No index, but seek index |
---|
| 983 | if ($index === false && $this->_nextOffset !== false) { |
---|
| 984 | $index = $this->_nextOffset; |
---|
| 985 | // Reset |
---|
| 986 | $this->_nextOffset = false; |
---|
| 987 | } |
---|
| 988 | |
---|
| 989 | // No index, start @ 0 by default |
---|
| 990 | if ($index === false) { |
---|
| 991 | $index = 0; |
---|
| 992 | } |
---|
| 993 | |
---|
| 994 | if (is_array($result)) { |
---|
| 995 | return $result[$index][0]; |
---|
| 996 | } |
---|
| 997 | |
---|
| 998 | $data = $result->getColumnMeta($index); |
---|
| 999 | |
---|
| 1000 | switch ($type) { |
---|
| 1001 | case 'flags': |
---|
| 1002 | // Flags in PDO getColumMeta() is incomplete, so we will get flags manually |
---|
| 1003 | return $this->_getAllColumnData($data, true); |
---|
| 1004 | case 'name': |
---|
| 1005 | return $data['name']; |
---|
| 1006 | case 'type': |
---|
| 1007 | return $this->_mapPdoType($data['native_type']); |
---|
| 1008 | case 'table': |
---|
| 1009 | return $data['table']; |
---|
| 1010 | // Getting all data (mysql_fetch_field) |
---|
| 1011 | case false: |
---|
| 1012 | // Calculate max_length of all field in the resultset |
---|
| 1013 | $rows = $result->fetchAll(PDO::FETCH_NUM); |
---|
| 1014 | $counter = count($rows); |
---|
| 1015 | $maxLength = 0; |
---|
| 1016 | for ($x = 0; $x < $counter; $x++) { |
---|
| 1017 | $len = strlen($rows[$x][$index]); |
---|
| 1018 | if ($len > $maxLength) { |
---|
| 1019 | $maxLength = $len; |
---|
| 1020 | } |
---|
| 1021 | } |
---|
| 1022 | return $this->_getAllColumnData($data, false, $maxLength); |
---|
| 1023 | default: |
---|
| 1024 | return null; |
---|
| 1025 | } |
---|
| 1026 | } |
---|
| 1027 | |
---|
| 1028 | /** |
---|
| 1029 | * Get all field data, mimick mysql_fetch_field functionality |
---|
| 1030 | * |
---|
| 1031 | * @param array $data |
---|
| 1032 | * @param boolean $simple |
---|
| 1033 | * @param int $maxLength |
---|
| 1034 | * |
---|
| 1035 | * @return object |
---|
| 1036 | */ |
---|
| 1037 | protected function _getAllColumnData($data, $simple = false, $maxLength = 0) |
---|
| 1038 | { |
---|
| 1039 | $type = $this->_mapPdoType($data['native_type']); |
---|
| 1040 | |
---|
| 1041 | // for zerofill/unsigned, we do a describe |
---|
| 1042 | $query = $this->mysql_query("DESCRIBE `{$data['table']}` `{$data['name']}`"); |
---|
| 1043 | $typeInner = $this->mysql_fetch_assoc($query); |
---|
| 1044 | |
---|
| 1045 | // Flags |
---|
| 1046 | if ($simple === true) { |
---|
| 1047 | $string = in_array('not_null', $data['flags']) ? 'not_null' : 'null'; |
---|
| 1048 | $string .= in_array('primary_key', $data['flags']) ? ' primary_key' : ''; |
---|
| 1049 | $string .= in_array('unique_key', $data['flags']) ? ' unique_key' : ''; |
---|
| 1050 | $string .= in_array('multiple_key', $data['flags']) ? ' multiple_key' : ''; |
---|
| 1051 | |
---|
| 1052 | $unSigned = strpos($typeInner['Type'], 'unsigned'); |
---|
| 1053 | if ($unSigned !== false) { |
---|
| 1054 | $string .= ' unsigned'; |
---|
| 1055 | } else { |
---|
| 1056 | $string .= strpos($typeInner['Type'], 'signed') !== false ? ' signed' : ''; |
---|
| 1057 | } |
---|
| 1058 | |
---|
| 1059 | $string .= strpos($typeInner['Type'], 'zerofill') !== false ? ' zerofill' : ''; |
---|
| 1060 | $string .= isset($typeInner['Extra']) ? ' ' . $typeInner['Extra'] : ''; |
---|
| 1061 | return $string; |
---|
| 1062 | } |
---|
| 1063 | |
---|
| 1064 | $return = array ( |
---|
| 1065 | 'name' => $data['name'], |
---|
| 1066 | 'table' => $data['table'], |
---|
| 1067 | 'def' => $typeInner['Default'], |
---|
| 1068 | 'max_length' => $maxLength, |
---|
| 1069 | 'not_null' => in_array('not_null', $data['flags']) ? 1 : 0, |
---|
| 1070 | 'primary_key' => in_array('primary_key', $data['flags']) ? 1 : 0, |
---|
| 1071 | 'multiple_key' => in_array('multiple_key', $data['flags']) ? 1 : 0, |
---|
| 1072 | 'unique_key' => in_array('unique_key', $data['flags']) ? 1 : 0, |
---|
| 1073 | 'numeric' => ($type == 'int') ? 1: 0, |
---|
| 1074 | 'blob' => ($type == 'blob') ? 1: 0, |
---|
| 1075 | 'type' => $type, |
---|
| 1076 | 'unsigned' => strpos($typeInner['Type'], 'unsigned') !== false ? 1 : 0, |
---|
| 1077 | 'zerofill' => strpos($typeInner['Type'], 'zerofill') !== false ? 1 : 0, |
---|
| 1078 | ); |
---|
| 1079 | |
---|
| 1080 | return (object) $return; |
---|
| 1081 | } |
---|
| 1082 | |
---|
| 1083 | /** |
---|
| 1084 | * Map PDO::TYPE_* to MySQL Type |
---|
| 1085 | * |
---|
| 1086 | * @param int $type PDO::TYPE_* |
---|
| 1087 | * |
---|
| 1088 | * @return string |
---|
| 1089 | */ |
---|
| 1090 | protected function _mapPdoType($type) |
---|
| 1091 | { |
---|
| 1092 | // Types enum defined @ http://lxr.php.net/xref/PHP_5_4/ext/mysqlnd/mysqlnd_enum_n_def.h#271 |
---|
| 1093 | $type = strtolower($type); |
---|
| 1094 | switch ($type) { |
---|
| 1095 | case 'tiny': |
---|
| 1096 | case 'short': |
---|
| 1097 | case 'long': |
---|
| 1098 | case 'longlong'; |
---|
| 1099 | case 'int24': |
---|
| 1100 | return 'int'; |
---|
| 1101 | case 'null': |
---|
| 1102 | return null; |
---|
| 1103 | case 'varchar': |
---|
| 1104 | case 'var_string': |
---|
| 1105 | case 'string': |
---|
| 1106 | return 'string'; |
---|
| 1107 | case 'blob': |
---|
| 1108 | case 'tiny_blob': |
---|
| 1109 | case 'long_blob': |
---|
| 1110 | return 'blob'; |
---|
| 1111 | default: |
---|
| 1112 | return $type; |
---|
| 1113 | } |
---|
| 1114 | } |
---|
| 1115 | |
---|
| 1116 | /** |
---|
| 1117 | * For now we handle single flags, future feature |
---|
| 1118 | * is to handle multiple flags with pipe | |
---|
| 1119 | * |
---|
| 1120 | * @param string |
---|
| 1121 | * |
---|
| 1122 | * @return array |
---|
| 1123 | */ |
---|
| 1124 | protected function _translateFlags($mysqlFlags) |
---|
| 1125 | { |
---|
| 1126 | if ($mysqlFlags == false || empty($mysqlFlags)) { |
---|
| 1127 | return array(); |
---|
| 1128 | } |
---|
| 1129 | |
---|
| 1130 | // Array it |
---|
| 1131 | if (!is_array($mysqlFlags)) { |
---|
| 1132 | $mysqlFlags = array($mysqlFlags); |
---|
| 1133 | } |
---|
| 1134 | |
---|
| 1135 | /* |
---|
| 1136 | * I am only adding flags that are mappable in PDO |
---|
| 1137 | * unfortunatly if you were using MySQL SSL, you will |
---|
| 1138 | * need to manually add that flag in using PDO constants |
---|
| 1139 | * located here: http://php.net/manual/en/ref.pdo-mysql.php |
---|
| 1140 | */ |
---|
| 1141 | $pdoParams = array(); |
---|
| 1142 | foreach ($mysqlFlags as $flag) { |
---|
| 1143 | switch ($flag) { |
---|
| 1144 | // CLIENT_FOUND_ROWS (found instead of affected rows) |
---|
| 1145 | case 2: |
---|
| 1146 | $params = array(PDO::MYSQL_ATTR_FOUND_ROWS => true); |
---|
| 1147 | break; |
---|
| 1148 | // CLIENT_COMPRESS (can use compression protocol) |
---|
| 1149 | case 32: |
---|
| 1150 | $params = array(PDO::MYSQL_ATTR_COMPRESS => true); |
---|
| 1151 | break; |
---|
| 1152 | // CLIENT_LOCAL_FILES (can use load data local) |
---|
| 1153 | case 128: |
---|
| 1154 | $params = array(PDO::MYSQL_ATTR_LOCAL_INFILE => true); |
---|
| 1155 | break; |
---|
| 1156 | // CLIENT_IGNORE_SPACE (ignore spaces before '(') |
---|
| 1157 | case 256: |
---|
| 1158 | $params = array(PDO::MYSQL_ATTR_IGNORE_SPACE => true); |
---|
| 1159 | break; |
---|
| 1160 | // Persistent connection |
---|
| 1161 | case 12: |
---|
| 1162 | $params = array(PDO::ATTR_PERSISTENT => true); |
---|
| 1163 | break; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | $pdoParams[] = $params; |
---|
| 1167 | } |
---|
| 1168 | |
---|
| 1169 | return $pdoParams; |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | /** |
---|
| 1173 | * Load data into array |
---|
| 1174 | * |
---|
| 1175 | * @param int $link |
---|
| 1176 | * @param PDO|PDOException|false $object |
---|
| 1177 | * |
---|
| 1178 | * @return void |
---|
| 1179 | */ |
---|
| 1180 | protected function _loadError($link, $object) |
---|
| 1181 | { |
---|
| 1182 | // Reset errors |
---|
| 1183 | if ($object === false || is_null($object)) { |
---|
| 1184 | $this->_params[$link]['errno'] = 0; |
---|
| 1185 | $this->_params[$link]['error'] = ""; |
---|
| 1186 | return; |
---|
| 1187 | } |
---|
| 1188 | // Set error |
---|
| 1189 | $this->_params[$link]['errno'] = $object->getCode(); |
---|
| 1190 | $this->_params[$link]['error'] = $object->getMessage(); |
---|
| 1191 | } |
---|
| 1192 | |
---|
| 1193 | /** |
---|
| 1194 | * get last db connection |
---|
| 1195 | * |
---|
| 1196 | * @param int $link |
---|
| 1197 | * @param boolean $validate |
---|
| 1198 | * |
---|
| 1199 | * @return int |
---|
| 1200 | */ |
---|
| 1201 | protected function _getLastLink($link, $validate = true) |
---|
| 1202 | { |
---|
| 1203 | if ($link === false) { |
---|
| 1204 | $link = count($this->_instances); |
---|
| 1205 | } |
---|
| 1206 | |
---|
| 1207 | if ( |
---|
| 1208 | $validate === true && |
---|
| 1209 | !isset($this->_instances[$link]) || |
---|
| 1210 | empty($this->_instances[$link])) { |
---|
| 1211 | if (isset($this->_instances[$link])) { |
---|
| 1212 | throw new MySQL2PDOException($this->_params[$link]['errno'] .': ' . $this->_params[$link]['error']); |
---|
| 1213 | } else { |
---|
| 1214 | throw new MySQL2PDOException('No db at instance #' . ($link - 1)); |
---|
| 1215 | } |
---|
| 1216 | } |
---|
| 1217 | |
---|
| 1218 | return $link; |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | /** |
---|
| 1222 | * Get result set and turn them into lengths |
---|
| 1223 | * |
---|
| 1224 | * @param array|object|null $resultSet |
---|
| 1225 | * @param boolean $elementId |
---|
| 1226 | * |
---|
| 1227 | * @return array |
---|
| 1228 | */ |
---|
| 1229 | protected function _mysqlGetLengths(&$resultSet = false, $elementId = false) |
---|
| 1230 | { |
---|
| 1231 | // If we don't have data |
---|
| 1232 | if (empty($resultSet) || is_null($resultSet)) { |
---|
| 1233 | if ($elementId === false) { |
---|
| 1234 | return null; |
---|
| 1235 | } |
---|
| 1236 | return 0; |
---|
| 1237 | } |
---|
| 1238 | |
---|
| 1239 | // Make sure it is an array |
---|
| 1240 | if (!is_array($resultSet)) { |
---|
| 1241 | $resultSet = (array) $resultSet; |
---|
| 1242 | } |
---|
| 1243 | |
---|
| 1244 | // Return lengths |
---|
| 1245 | $resultSet = array_map('strlen', $resultSet); |
---|
| 1246 | |
---|
| 1247 | if ($elementId === false) { |
---|
| 1248 | return $resultSet; |
---|
| 1249 | } |
---|
| 1250 | |
---|
| 1251 | return $resultSet[$elementId]; |
---|
| 1252 | } |
---|
| 1253 | } |
---|
| 1254 | |
---|
| 1255 | /** |
---|
| 1256 | * This file will handle the conversion from |
---|
| 1257 | * mysql_* functions to our object - So that I |
---|
| 1258 | * don't duplicate documentation, visit link of |
---|
| 1259 | * the functions for more info on the params. Any |
---|
| 1260 | * custom params added or changes will be noted. |
---|
| 1261 | * |
---|
| 1262 | * Note: Since this is handled by our object, the DB |
---|
| 1263 | * resource link will be the subscript of the database |
---|
| 1264 | * connection, 0-X, where X is INT. If not passed, assumed |
---|
| 1265 | * subscript 0. |
---|
| 1266 | * |
---|
| 1267 | * @author Aziz S. Hussain <azizsaleh@gmail.com> |
---|
| 1268 | * @copyright GPL license |
---|
| 1269 | * @license http://www.gnu.org/copyleft/gpl.html |
---|
| 1270 | * @link http://www.AzizSaleh.com |
---|
| 1271 | */ |
---|
| 1272 | |
---|
| 1273 | function mysql_add_existing_connection($dbh) |
---|
| 1274 | { |
---|
| 1275 | return MySQL::getInstance()->mysql_add_existing_connection($dbh); |
---|
| 1276 | } |
---|
| 1277 | |
---|
| 1278 | // http://www.php.net/manual/en/function.mysql-connect.php |
---|
| 1279 | function mysql_connect($server, $username, $password, $new_link = false, $client_flags = false) |
---|
| 1280 | { |
---|
| 1281 | return MySQL::getInstance()->mysql_connect($server, $username, $password, $new_link, $client_flags); |
---|
| 1282 | } |
---|
| 1283 | |
---|
| 1284 | // http://www.php.net/manual/en/function.mysql-connect.php |
---|
| 1285 | function mysql_pconnect($server, $username, $password, $new_link = false, $client_flags = false) |
---|
| 1286 | { |
---|
| 1287 | return MySQL::getInstance()->mysql_pconnect($server, $username, $password, $new_link, $client_flags); |
---|
| 1288 | } |
---|
| 1289 | |
---|
| 1290 | // http://www.php.net/manual/en/function.mysql-select-db.php |
---|
| 1291 | function mysql_select_db($database_name, $link = false) |
---|
| 1292 | { |
---|
| 1293 | return MySQL::getInstance()->mysql_select_db($database_name, $link); |
---|
| 1294 | } |
---|
| 1295 | |
---|
| 1296 | function mysql_selectdb($database_name, $link = false) |
---|
| 1297 | { |
---|
| 1298 | return MySQL::getInstance()->mysql_select_db($database_name, $link); |
---|
| 1299 | } |
---|
| 1300 | |
---|
| 1301 | // http://www.php.net/manual/en/function.mysql-query.php |
---|
| 1302 | function mysql_query($query, $link = false) |
---|
| 1303 | { |
---|
| 1304 | return MySQL::getInstance()->mysql_query($query, $link); |
---|
| 1305 | } |
---|
| 1306 | |
---|
| 1307 | // http://www.php.net/manual/en/function.mysql-real-escape-string.php |
---|
| 1308 | function mysql_real_escape_string($string, $link = false) |
---|
| 1309 | { |
---|
| 1310 | return MySQL::getInstance()->mysql_real_escape_string($string, $link); |
---|
| 1311 | } |
---|
| 1312 | |
---|
| 1313 | // http://www.php.net/manual/en/function.mysql-escape-string.php |
---|
| 1314 | function mysql_escape_string($string, $link = false) |
---|
| 1315 | { |
---|
| 1316 | return MySQL::getInstance()->mysql_escape_string($string, $link); |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | // http://www.php.net/manual/en/function.mysql-fetch-array.php |
---|
| 1320 | function mysql_fetch_array(&$result, $result_type = MYSQL_BOTH) |
---|
| 1321 | { |
---|
| 1322 | return MySQL::getInstance()->mysql_fetch_array($result, $result_type); |
---|
| 1323 | } |
---|
| 1324 | |
---|
| 1325 | // http://www.php.net/manual/en/function.mysql-fetch-assoc.php |
---|
| 1326 | function mysql_fetch_assoc(&$result) |
---|
| 1327 | { |
---|
| 1328 | return MySQL::getInstance()->mysql_fetch_assoc($result); |
---|
| 1329 | } |
---|
| 1330 | |
---|
| 1331 | // http://www.php.net/manual/en/function.mysql-fetch-row.php |
---|
| 1332 | function mysql_fetch_row(&$result) |
---|
| 1333 | { |
---|
| 1334 | return MySQL::getInstance()->mysql_fetch_row($result); |
---|
| 1335 | } |
---|
| 1336 | |
---|
| 1337 | // http://www.php.net/manual/en/function.mysql-fetch-object.php |
---|
| 1338 | function mysql_fetch_object(&$result) |
---|
| 1339 | { |
---|
| 1340 | return MySQL::getInstance()->mysql_fetch_object($result); |
---|
| 1341 | } |
---|
| 1342 | |
---|
| 1343 | // http://www.php.net/manual/en/function.mysql-ping.php |
---|
| 1344 | function mysql_ping($link = false) |
---|
| 1345 | { |
---|
| 1346 | return MySQL::getInstance()->mysql_ping($link); |
---|
| 1347 | } |
---|
| 1348 | |
---|
| 1349 | // http://www.php.net/manual/en/function.mysql-errno.php |
---|
| 1350 | function mysql_errno($link = false) |
---|
| 1351 | { |
---|
| 1352 | return MySQL::getInstance()->mysql_errno($link); |
---|
| 1353 | } |
---|
| 1354 | |
---|
| 1355 | // http://www.php.net/manual/en/function.mysql-error.php |
---|
| 1356 | function mysql_error($link = false) |
---|
| 1357 | { |
---|
| 1358 | return MySQL::getInstance()->mysql_error($link); |
---|
| 1359 | } |
---|
| 1360 | |
---|
| 1361 | // http://www.php.net/manual/en/function.mysql-affected-rows.php |
---|
| 1362 | function mysql_affected_rows($link = false) |
---|
| 1363 | { |
---|
| 1364 | return MySQL::getInstance()->mysql_affected_rows($link); |
---|
| 1365 | } |
---|
| 1366 | |
---|
| 1367 | // http://www.php.net/manual/en/function.mysql-client-encoding.php |
---|
| 1368 | function mysql_client_encoding($link = false) |
---|
| 1369 | { |
---|
| 1370 | return MySQL::getInstance()->mysql_client_encoding($link); |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | // http://www.php.net/manual/en/function.mysql-close.php |
---|
| 1374 | function mysql_close($link = false) |
---|
| 1375 | { |
---|
| 1376 | return MySQL::getInstance()->mysql_close($link); |
---|
| 1377 | } |
---|
| 1378 | |
---|
| 1379 | // http://www.php.net/manual/en/function.mysql-create-db.php |
---|
| 1380 | function mysql_create_db($database_name, $link = false) |
---|
| 1381 | { |
---|
| 1382 | return MySQL::getInstance()->mysql_create_db($database_name, $link); |
---|
| 1383 | } |
---|
| 1384 | |
---|
| 1385 | function mysql_createdb($database_name, $link = false) |
---|
| 1386 | { |
---|
| 1387 | return MySQL::getInstance()->mysql_create_db($database_name, $link); |
---|
| 1388 | } |
---|
| 1389 | |
---|
| 1390 | // http://www.php.net/manual/en/function.mysql-data-seek.php |
---|
| 1391 | function mysql_data_seek($result, $row_number) |
---|
| 1392 | { |
---|
| 1393 | return MySQL::getInstance()->mysql_data_seek($result, $row_number); |
---|
| 1394 | } |
---|
| 1395 | |
---|
| 1396 | // http://www.php.net/manual/en/function.mysql-list-dbs.php |
---|
| 1397 | function mysql_list_dbs($link = false) |
---|
| 1398 | { |
---|
| 1399 | return MySQL::getInstance()->mysql_list_dbs($link); |
---|
| 1400 | } |
---|
| 1401 | |
---|
| 1402 | function mysql_listdbs($link = false) |
---|
| 1403 | { |
---|
| 1404 | return MySQL::getInstance()->mysql_list_dbs($link); |
---|
| 1405 | } |
---|
| 1406 | |
---|
| 1407 | // http://www.php.net/manual/en/function.mysql-db-name.php |
---|
| 1408 | function mysql_db_name(&$result, $row, $field = 'Database') |
---|
| 1409 | { |
---|
| 1410 | return MySQL::getInstance()->mysql_db_name($result, $row, $field); |
---|
| 1411 | } |
---|
| 1412 | |
---|
| 1413 | function mysql_dbname(&$result, $row, $field = 'Database') |
---|
| 1414 | { |
---|
| 1415 | return MySQL::getInstance()->mysql_db_name($result, $row, $field); |
---|
| 1416 | } |
---|
| 1417 | |
---|
| 1418 | // http://www.php.net/manual/en/function.mysql-db-query.php |
---|
| 1419 | function mysql_db_query($databaseName, $query, $link = false) |
---|
| 1420 | { |
---|
| 1421 | return MySQL::getInstance()->mysql_db_query($databaseName, $query, $link); |
---|
| 1422 | } |
---|
| 1423 | |
---|
| 1424 | // http://www.php.net/manual/en/function.mysql-drop-db.php |
---|
| 1425 | function mysql_drop_db($databaseName, $link = false) |
---|
| 1426 | { |
---|
| 1427 | return MySQL::getInstance()->mysql_drop_db($databaseName, $link); |
---|
| 1428 | } |
---|
| 1429 | |
---|
| 1430 | function mysql_dropdb($databaseName, $link = false) |
---|
| 1431 | { |
---|
| 1432 | return MySQL::getInstance()->mysql_drop_db($databaseName, $link); |
---|
| 1433 | } |
---|
| 1434 | |
---|
| 1435 | // http://www.php.net/manual/en/function.mysql-unbuffered-query.php |
---|
| 1436 | function mysql_unbuffered_query($query, $link = false) |
---|
| 1437 | { |
---|
| 1438 | return MySQL::getInstance()->mysql_unbuffered_query($query, $link); |
---|
| 1439 | } |
---|
| 1440 | |
---|
| 1441 | // http://www.php.net/manual/en/function.mysql-thread-id.php |
---|
| 1442 | function mysql_thread_id($link = false) |
---|
| 1443 | { |
---|
| 1444 | return MySQL::getInstance()->mysql_thread_id($link); |
---|
| 1445 | } |
---|
| 1446 | |
---|
| 1447 | // http://www.php.net/manual/en/function.mysql-list-tables.php |
---|
| 1448 | function mysql_list_tables($databaseName, $link = false) |
---|
| 1449 | { |
---|
| 1450 | return MySQL::getInstance()->mysql_list_tables($databaseName, $link); |
---|
| 1451 | } |
---|
| 1452 | |
---|
| 1453 | function mysql_listtables($databaseName, $link = false) |
---|
| 1454 | { |
---|
| 1455 | return MySQL::getInstance()->mysql_list_tables($databaseName, $link); |
---|
| 1456 | } |
---|
| 1457 | |
---|
| 1458 | // http://www.php.net/manual/en/function.mysql-tablename.php |
---|
| 1459 | function mysql_tablename(&$result, $row) |
---|
| 1460 | { |
---|
| 1461 | return MySQL::getInstance()->mysql_tablename($result, $row); |
---|
| 1462 | } |
---|
| 1463 | |
---|
| 1464 | // http://www.php.net/manual/en/function.mysql-stat.php |
---|
| 1465 | function mysql_stat($link = false) |
---|
| 1466 | { |
---|
| 1467 | return MySQL::getInstance()->mysql_stat($link); |
---|
| 1468 | } |
---|
| 1469 | |
---|
| 1470 | // http://www.php.net/manual/en/function.mysql-set-charset.php |
---|
| 1471 | function mysql_set_charset($charset, $link = false) |
---|
| 1472 | { |
---|
| 1473 | return MySQL::getInstance()->mysql_set_charset($charset, $link); |
---|
| 1474 | } |
---|
| 1475 | |
---|
| 1476 | // http://www.php.net/manual/en/function.mysql-result.php |
---|
| 1477 | function mysql_result(&$result, $rows, $field = false) |
---|
| 1478 | { |
---|
| 1479 | return MySQL::getInstance()->mysql_result($result, $rows, $field); |
---|
| 1480 | } |
---|
| 1481 | |
---|
| 1482 | // http://www.php.net/manual/en/function.mysql-list-processes.php |
---|
| 1483 | function mysql_list_processes($link = false) |
---|
| 1484 | { |
---|
| 1485 | return MySQL::getInstance()->mysql_list_processes($link); |
---|
| 1486 | } |
---|
| 1487 | |
---|
| 1488 | // http://www.php.net/manual/en/function.mysql-insert-id.php |
---|
| 1489 | function mysql_insert_id($link = false) |
---|
| 1490 | { |
---|
| 1491 | return MySQL::getInstance()->mysql_insert_id($link); |
---|
| 1492 | } |
---|
| 1493 | |
---|
| 1494 | // http://www.php.net/manual/en/function.mysql-get-server-info.php |
---|
| 1495 | function mysql_get_server_info($link = false) |
---|
| 1496 | { |
---|
| 1497 | return MySQL::getInstance()->mysql_get_server_info($link); |
---|
| 1498 | } |
---|
| 1499 | |
---|
| 1500 | // http://www.php.net/manual/en/function.mysql-get-proto-info.php |
---|
| 1501 | function mysql_get_proto_info($link = false) |
---|
| 1502 | { |
---|
| 1503 | return MySQL::getInstance()->mysql_get_proto_info($link); |
---|
| 1504 | } |
---|
| 1505 | |
---|
| 1506 | // http://www.php.net/manual/en/function.mysql-get-host-info.php |
---|
| 1507 | function mysql_get_host_info($link = false) |
---|
| 1508 | { |
---|
| 1509 | return MySQL::getInstance()->mysql_get_host_info($link); |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | // http://www.php.net/manual/en/function.mysql-get-client-info.php |
---|
| 1513 | function mysql_get_client_info($link = false) |
---|
| 1514 | { |
---|
| 1515 | return MySQL::getInstance()->mysql_get_client_info($link); |
---|
| 1516 | } |
---|
| 1517 | |
---|
| 1518 | // http://www.php.net/manual/en/function.mysql-free-result.php |
---|
| 1519 | function mysql_free_result(&$result) |
---|
| 1520 | { |
---|
| 1521 | return MySQL::getInstance()->mysql_free_result($result); |
---|
| 1522 | } |
---|
| 1523 | |
---|
| 1524 | function mysql_freeresult(&$result) |
---|
| 1525 | { |
---|
| 1526 | return MySQL::getInstance()->mysql_free_result($result); |
---|
| 1527 | } |
---|
| 1528 | |
---|
| 1529 | // http://www.php.net/manual/en/function.mysql-fetch-lengths.php |
---|
| 1530 | function mysql_fetch_lengths(&$result) |
---|
| 1531 | { |
---|
| 1532 | return MySQL::getInstance()->mysql_fetch_lengths($result); |
---|
| 1533 | } |
---|
| 1534 | |
---|
| 1535 | // http://www.php.net/manual/en/function.mysql-list-fields.php |
---|
| 1536 | function mysql_list_fields($databaseName, $tableName, $link = false) |
---|
| 1537 | { |
---|
| 1538 | return MySQL::getInstance()->mysql_list_fields($databaseName, $tableName, $link); |
---|
| 1539 | } |
---|
| 1540 | |
---|
| 1541 | function mysql_listfields($databaseName, $tableName, $link = false) |
---|
| 1542 | { |
---|
| 1543 | return MySQL::getInstance()->mysql_list_fields($databaseName, $tableName, $link); |
---|
| 1544 | } |
---|
| 1545 | |
---|
| 1546 | // http://www.php.net/manual/en/function.mysql-field-len.php |
---|
| 1547 | function mysql_field_len(&$result, $fieldOffset = false) |
---|
| 1548 | { |
---|
| 1549 | return MySQL::getInstance()->mysql_field_len($result, $fieldOffset); |
---|
| 1550 | } |
---|
| 1551 | |
---|
| 1552 | function mysql_fieldlen(&$result, $fieldOffset = false) |
---|
| 1553 | { |
---|
| 1554 | return MySQL::getInstance()->mysql_field_len($result, $fieldOffset); |
---|
| 1555 | } |
---|
| 1556 | |
---|
| 1557 | // http://www.php.net/manual/en/function.mysql-field-flags.php |
---|
| 1558 | function mysql_field_flags(&$result, $fieldOffset = false) |
---|
| 1559 | { |
---|
| 1560 | return MySQL::getInstance()->mysql_field_flags($result, $fieldOffset); |
---|
| 1561 | } |
---|
| 1562 | |
---|
| 1563 | function mysql_fieldflags(&$result, $fieldOffset = false) |
---|
| 1564 | { |
---|
| 1565 | return MySQL::getInstance()->mysql_field_flags($result, $fieldOffset); |
---|
| 1566 | } |
---|
| 1567 | |
---|
| 1568 | // http://www.php.net/manual/en/function.mysql-field-name.php |
---|
| 1569 | function mysql_field_name(&$result, $fieldOffset = false) |
---|
| 1570 | { |
---|
| 1571 | return MySQL::getInstance()->mysql_field_name($result, $fieldOffset); |
---|
| 1572 | } |
---|
| 1573 | |
---|
| 1574 | function mysql_fieldname(&$result, $fieldOffset = false) |
---|
| 1575 | { |
---|
| 1576 | return MySQL::getInstance()->mysql_field_name($result, $fieldOffset); |
---|
| 1577 | } |
---|
| 1578 | |
---|
| 1579 | // http://www.php.net/manual/en/function.mysql-field-type.php |
---|
| 1580 | function mysql_field_type(&$result, $fieldOffset = false) |
---|
| 1581 | { |
---|
| 1582 | return MySQL::getInstance()->mysql_field_type($result, $fieldOffset); |
---|
| 1583 | } |
---|
| 1584 | |
---|
| 1585 | function mysql_fieldtype(&$result, $fieldOffset = false) |
---|
| 1586 | { |
---|
| 1587 | return MySQL::getInstance()->mysql_field_type($result, $fieldOffset); |
---|
| 1588 | } |
---|
| 1589 | |
---|
| 1590 | // http://www.php.net/manual/en/function.mysql-field-table.php |
---|
| 1591 | function mysql_field_table(&$result, $fieldOffset = false) |
---|
| 1592 | { |
---|
| 1593 | return MySQL::getInstance()->mysql_field_table($result, $fieldOffset); |
---|
| 1594 | } |
---|
| 1595 | |
---|
| 1596 | function mysql_fieldtable(&$result, $fieldOffset = false) |
---|
| 1597 | { |
---|
| 1598 | return MySQL::getInstance()->mysql_field_table($result, $fieldOffset); |
---|
| 1599 | } |
---|
| 1600 | |
---|
| 1601 | // http://www.php.net/manual/en/function.mysql-field-seek.php |
---|
| 1602 | function mysql_field_seek(&$result, $fieldOffset = false) |
---|
| 1603 | { |
---|
| 1604 | return MySQL::getInstance()->mysql_field_seek($result, $fieldOffset); |
---|
| 1605 | } |
---|
| 1606 | |
---|
| 1607 | // http://www.php.net/manual/en/function.mysql-fetch-field.php |
---|
| 1608 | function mysql_fetch_field(&$result, $fieldOffset = false) |
---|
| 1609 | { |
---|
| 1610 | return MySQL::getInstance()->mysql_fetch_field($result, $fieldOffset); |
---|
| 1611 | } |
---|
| 1612 | |
---|
| 1613 | // http://www.php.net/manual/en/function.mysql-num-fields.php |
---|
| 1614 | function mysql_num_fields($result) |
---|
| 1615 | { |
---|
| 1616 | return MySQL::getInstance()->mysql_num_fields($result); |
---|
| 1617 | } |
---|
| 1618 | |
---|
| 1619 | function mysql_numfields($result) |
---|
| 1620 | { |
---|
| 1621 | return MySQL::getInstance()->mysql_num_fields($result); |
---|
| 1622 | } |
---|
| 1623 | |
---|
| 1624 | // http://www.php.net/manual/en/function.mysql-num-rows.php |
---|
| 1625 | function mysql_num_rows($result) |
---|
| 1626 | { |
---|
| 1627 | return MySQL::getInstance()->mysql_num_rows($result); |
---|
| 1628 | } |
---|
| 1629 | |
---|
| 1630 | function mysql_numrows($result) |
---|
| 1631 | { |
---|
| 1632 | return MySQL::getInstance()->mysql_num_rows($result); |
---|
| 1633 | } |
---|
| 1634 | |
---|
| 1635 | // http://php.net/manual/en/function.mysql-info.php |
---|
| 1636 | function mysql_info($link = false) |
---|
| 1637 | { |
---|
| 1638 | return MySQL::getInstance()->mysql_info($link); |
---|
| 1639 | } |
---|
| 1640 | |
---|
| 1641 | // Close all connections |
---|
| 1642 | function mysql_close_all() |
---|
| 1643 | { |
---|
| 1644 | return MySQL::getInstance()->mysql_close_all(); |
---|
| 1645 | } |
---|
| 1646 | |
---|
| 1647 | // is_resource function over ride |
---|
| 1648 | function is_resource_custom($resource) |
---|
| 1649 | { |
---|
| 1650 | return MySQL::getInstance()->is_resource($resource); |
---|
| 1651 | } |
---|
| 1652 | |
---|
| 1653 | // get_resource_type_custom function over ride |
---|
| 1654 | function get_resource_type_custom($resource) |
---|
| 1655 | { |
---|
| 1656 | return MySQL::getInstance()->get_resource_type($resource); |
---|
| 1657 | } |
---|
| 1658 | |
---|
| 1659 | } |
---|