source: trunk/polyfill/mysql.inc.php

Last change on this file was 812, checked in by anonymous, 6 weeks ago

Fix depreciation notices

File size: 52.9 KB
Line 
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 */
18if (!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
178                $this->_instances[$usePosition] = new PDO($dsn, $username, $password, $flags);
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;
213                return $this->mysql_query("USE `{$databaseName}`", $link);
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
267            if ($result === false || $result === null) {
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            if ('' == (string)$string) {
836                return '';
837            }
838
839            $link = $this->_getLastLink($link);
840
841            try {
842                $string = $this->_instances[$link]->quote($string);
843                $this->_loadError($link, false);
844                return substr($string, 1, -1);
845            } catch (PDOException $e) {
846                $this->_loadError($link, $e);
847                return false;
848            }
849
850            return false;
851        }
852
853        /**
854         * mysql_escape_string
855         * http://www.php.net/manual/en/function.mysql-escape-string.php
856         */
857        public function mysql_escape_string($string, $link = false)
858        {
859            $link = $this->_getLastLink($link, false);
860            return $this->mysql_real_escape_string($string, $link);
861        }
862
863        /**
864         * mysql_info
865         *
866         * Not sure how to get the actual result message from MySQL
867         * so the best I could do was to get the affected rows
868         * and construct a message that way. If you have a better way
869         * or know of a more accurate method, send it to me @
870         * azizsaleh@gmail.com and I'll update the code with it. All I got is
871         * the affected rows, so it will be missing changed, warnings,
872         * skipped, and rows matched
873         *
874         * http://www.php.net/manual/en/function.mysql-escape-string.php
875         */
876        public function mysql_info($link = false)
877        {
878            $link = $this->_getLastLink($link);
879
880            $query = $this->_params[$link]['lastQuery'];
881
882            if (!isset($query->queryString)) {
883                return false;
884            }
885
886            $affected = $this->_params[$link]['rowCount'];
887
888            if (strtoupper(substr($query->queryString, 0, 5)) == 'INSERT INTO') {
889                return "Records: {$affected}  Duplicates: 0  Warnings: 0";
890            }
891
892            if (strtoupper(substr($query->queryString, 0, 9)) == 'LOAD DATA') {
893                return "Records: {$affected}  Deleted: 0  Skipped: 0  Warnings: 0";
894            }
895
896            if (strtoupper(substr($query->queryString, 0, 11)) == 'ALTER TABLE') {
897                return "Records: {$affected}  Duplicates: 0  Warnings: 0";
898            }
899
900            if (strtoupper(substr($query->queryString, 0, 6)) == 'UPDATE') {
901                return "Rows matched: {$affected}  Changed: {$affected}  Warnings: 0";
902            }
903
904            if (strtoupper(substr($query->queryString, 0, 6)) == 'DELETE') {
905                return "Records: 0  Deleted: {$affected}  Skipped: 0  Warnings: 0";
906            }
907
908            return false;
909        }
910
911        /**
912         * Close all connections
913         *
914         * @return void
915         */
916        public function mysql_close_all()
917        {
918            // Free connections
919            foreach ($this->_instances as $id => $pdo) {
920                $this->_instances[$id] = null;
921            }
922
923            // Reset arrays
924            $this->_instances = array(array());
925            $this->_params    = array();
926        }
927
928        /**
929         * is_resource function over ride
930         *
931         * @param RESOURCE $resource
932         *
933         * @return boolean
934         */
935        public function is_resource($resource)
936        {
937            // Check for a mysql result
938            if (is_object($resource) && $resource instanceof PDOStatement) {
939                return true;
940            // Check if it is a mysql instance
941            } elseif (isset($this->_instances[$resource]) && !empty($this->_instances[$resource])) {
942                return true;
943            }
944
945            return is_resource($resource);
946        }
947
948        /**
949         * get_resource_type function over ride
950         *
951         * @param RESOURCE $resource
952         *
953         * @return boolean
954         */
955        public function get_resource_type($resource)
956        {
957            // mysql result resource type
958            if (is_object($resource) && $resource instanceof PDOStatement) {
959                return 'mysql result';
960            }
961
962            // Check if it is a mysql instance
963            if (isset($this->_instances[$resource]) && !empty($this->_instances[$resource])) {
964                // Check type
965                if ($this->_params[$resource]['clientFlags'] == PDO::ATTR_PERSISTENT) {
966                    return 'mysql link persistent';
967                } else {
968                    return 'mysql link';
969                }
970            }
971
972            return get_resource_type($resource);
973        }
974
975        /**
976         * Get column meta information
977         *
978         * @param   object          $result
979         * @param   enum|boolean    $type   flags|name|type|table|len
980         * @param   int             $index
981         *
982         * @return  mixed
983         */
984        protected function _getColumnMeta(&$result, $type, $index)
985        {
986            // No index, but seek index
987            if ($index === false && $this->_nextOffset !== false) {
988                $index = $this->_nextOffset;
989                // Reset
990                $this->_nextOffset = false;
991            }
992
993            // No index, start @ 0 by default
994            if ($index === false) {
995                $index = 0;
996            }
997
998            if (is_array($result)) {
999                return $result[$index][0];
1000            }
1001
1002            $data = $result->getColumnMeta($index);
1003
1004            switch ($type) {
1005                case 'flags':
1006                    // Flags in PDO getColumMeta() is incomplete, so we will get flags manually
1007                    return $this->_getAllColumnData($data, true);
1008                case 'name':
1009                    return $data['name'];
1010                case 'type':
1011                    return $this->_mapPdoType($data['native_type']);
1012                case 'table':
1013                    return $data['table'];
1014                // Getting all data (mysql_fetch_field)
1015                case false:
1016                    // Calculate max_length of all field in the resultset
1017                    $rows = $result->fetchAll(PDO::FETCH_NUM);
1018                    $counter = count($rows);
1019                    $maxLength = 0;
1020                    for ($x = 0; $x < $counter; $x++) {
1021                        $len = strlen($rows[$x][$index]);
1022                        if ($len > $maxLength) {
1023                            $maxLength = $len;
1024                        }
1025                    }
1026                    return $this->_getAllColumnData($data, false, $maxLength);
1027                default:
1028                    return null;
1029            }
1030        }
1031
1032        /**
1033         * Get all field data, mimick mysql_fetch_field functionality
1034         *
1035         * @param   array   $data
1036         * @param   boolean $simple
1037         * @param   int     $maxLength
1038         *
1039         * @return  object
1040         */
1041        protected function _getAllColumnData($data, $simple = false, $maxLength = 0)
1042        {
1043            $type = $this->_mapPdoType($data['native_type']);
1044
1045            // for zerofill/unsigned, we do a describe
1046            $query = $this->mysql_query("DESCRIBE `{$data['table']}` `{$data['name']}`");
1047            $typeInner = $this->mysql_fetch_assoc($query);
1048
1049            // Flags
1050            if ($simple === true) {
1051                $string = in_array('not_null', $data['flags']) ? 'not_null' : 'null';
1052                $string .= in_array('primary_key', $data['flags']) ? ' primary_key' : '';
1053                $string .= in_array('unique_key', $data['flags']) ? ' unique_key' : '';
1054                $string .= in_array('multiple_key', $data['flags']) ? ' multiple_key' : '';
1055
1056                $unSigned = strpos($typeInner['Type'], 'unsigned');
1057                if ($unSigned !== false) {
1058                    $string .= ' unsigned';
1059                } else {
1060                    $string .= strpos($typeInner['Type'], 'signed') !== false ? ' signed' : '';
1061                }
1062
1063                $string .= strpos($typeInner['Type'], 'zerofill') !== false ? ' zerofill' : '';
1064                $string .= isset($typeInner['Extra']) ? ' ' . $typeInner['Extra'] : '';
1065                return $string;
1066            }
1067
1068            $return = array (
1069                'name'          => $data['name'],
1070                'table'         => $data['table'],
1071                'def'           => $typeInner['Default'],
1072                'max_length'    => $maxLength,
1073                'not_null'      => in_array('not_null', $data['flags']) ? 1 : 0,
1074                'primary_key'   => in_array('primary_key', $data['flags']) ? 1 : 0,
1075                'multiple_key'  => in_array('multiple_key', $data['flags']) ? 1 : 0,
1076                'unique_key'    => in_array('unique_key', $data['flags']) ? 1 : 0,
1077                'numeric'       => ($type == 'int') ? 1: 0,
1078                'blob'          => ($type == 'blob') ? 1: 0,
1079                'type'          => $type,
1080                'unsigned'      => strpos($typeInner['Type'], 'unsigned') !== false ? 1 : 0,
1081                'zerofill'      => strpos($typeInner['Type'], 'zerofill') !== false ? 1 : 0,
1082            );
1083
1084            return (object) $return;
1085        }
1086
1087        /**
1088         * Map PDO::TYPE_* to MySQL Type
1089         *
1090         * @param int   $type   PDO::TYPE_*
1091         *
1092         * @return string
1093         */
1094        protected function _mapPdoType($type)
1095        {
1096            // Types enum defined @ http://lxr.php.net/xref/PHP_5_4/ext/mysqlnd/mysqlnd_enum_n_def.h#271
1097            $type = strtolower($type);
1098            switch ($type) {
1099                case 'tiny':
1100                case 'short':
1101                case 'long':
1102                case 'longlong';
1103                case 'int24':
1104                    return 'int';
1105                case 'null':
1106                    return null;
1107                case 'varchar':
1108                case 'var_string':
1109                case 'string':
1110                    return 'string';
1111                case 'blob':
1112                case 'tiny_blob':
1113                case 'long_blob':
1114                    return 'blob';
1115                default:
1116                    return $type;
1117            }
1118        }
1119
1120        /**
1121         * For now we handle single flags, future feature
1122         * is to handle multiple flags with pipe |
1123         *
1124         * @param  string
1125         *
1126         * @return array
1127         */
1128        protected function _translateFlags($mysqlFlags)
1129        {
1130            if ($mysqlFlags == false || empty($mysqlFlags)) {
1131                return array();
1132            }
1133
1134            // Array it
1135            if (!is_array($mysqlFlags)) {
1136                $mysqlFlags = array($mysqlFlags);
1137            }
1138
1139            /*
1140             * I am only adding flags that are mappable in PDO
1141             * unfortunatly if you were using MySQL SSL, you will
1142             * need to manually add that flag in using PDO constants
1143             * located here: http://php.net/manual/en/ref.pdo-mysql.php
1144             */
1145            $pdoParams = array();
1146            foreach ($mysqlFlags as $flag) {
1147                switch ($flag) {
1148                // CLIENT_FOUND_ROWS (found instead of affected rows)
1149                    case 2:
1150                        $params = array(PDO::MYSQL_ATTR_FOUND_ROWS => true);
1151                        break;
1152                    // CLIENT_COMPRESS (can use compression protocol)
1153                    case 32:
1154                        $params = array(PDO::MYSQL_ATTR_COMPRESS => true);
1155                        break;
1156                    // CLIENT_LOCAL_FILES (can use load data local)
1157                    case 128:
1158                        $params = array(PDO::MYSQL_ATTR_LOCAL_INFILE => true);
1159                        break;
1160                    // CLIENT_IGNORE_SPACE (ignore spaces before '(')
1161                    case 256:
1162                        $params = array(PDO::MYSQL_ATTR_IGNORE_SPACE => true);
1163                        break;
1164                    // Persistent connection
1165                    case 12:
1166                        $params = array(PDO::ATTR_PERSISTENT => true);
1167                        break;
1168                }
1169
1170                $pdoParams[] = $params;
1171            }
1172
1173            return $pdoParams;
1174        }
1175
1176        /**
1177         * Load data into array
1178         *
1179         * @param int                       $link
1180         * @param PDO|PDOException|false    $object
1181         *
1182         * @return void
1183         */
1184        protected function _loadError($link, $object)
1185        {
1186            // Reset errors
1187            if ($object === false || is_null($object)) {
1188                $this->_params[$link]['errno'] = 0;
1189                $this->_params[$link]['error'] = "";
1190                return;
1191            }
1192            // Set error
1193            $this->_params[$link]['errno'] = $object->getCode();
1194            $this->_params[$link]['error'] = $object->getMessage();
1195        }
1196
1197        /**
1198         * get last db connection
1199         *
1200         * @param   int     $link
1201         * @param   boolean $validate
1202         *
1203         * @return int
1204         */
1205        protected function _getLastLink($link, $validate = true)
1206        {
1207            if ($link === false) {
1208                $link = count($this->_instances);
1209            }
1210
1211            if (
1212              $validate === true &&
1213              !isset($this->_instances[$link]) ||
1214              empty($this->_instances[$link])) {
1215                if (isset($this->_instances[$link])) {
1216                    throw new MySQL2PDOException($this->_params[$link]['errno'] .': ' . $this->_params[$link]['error']);
1217                } else {
1218                    throw new MySQL2PDOException('No db at instance #' . ($link - 1));
1219                }
1220            }
1221
1222            return $link;
1223        }
1224
1225        /**
1226         * Get result set and turn them into lengths
1227         *
1228         * @param   array|object|null $resultSet
1229         * @param   boolean           $elementId
1230         *
1231         * @return  array
1232         */
1233        protected function _mysqlGetLengths(&$resultSet = false, $elementId = false)
1234        {
1235            // If we don't have data
1236            if (empty($resultSet) || is_null($resultSet)) {
1237                if ($elementId === false) {
1238                    return null;
1239                }
1240                return 0;
1241            }
1242
1243            // Make sure it is an array
1244            if (!is_array($resultSet)) {
1245                $resultSet = (array) $resultSet;
1246            }
1247
1248            // Return lengths
1249            $resultSet = array_map('strlen', $resultSet);
1250
1251            if ($elementId === false) {
1252                return $resultSet;
1253            }
1254
1255            return $resultSet[$elementId];
1256        }
1257    }
1258
1259    /**
1260     * This file will handle the conversion from
1261     * mysql_* functions to our object - So that I
1262     * don't duplicate documentation, visit link of
1263     * the functions for more info on the params. Any
1264     * custom params added or changes will be noted.
1265     *
1266     * Note: Since this is handled by our object, the DB
1267     * resource link will be the subscript of the database
1268     * connection, 0-X, where X is INT. If not passed, assumed
1269     * subscript 0.
1270     *
1271     * @author    Aziz S. Hussain <azizsaleh@gmail.com>
1272     * @copyright GPL license
1273     * @license   http://www.gnu.org/copyleft/gpl.html
1274     * @link      http://www.AzizSaleh.com
1275     */
1276
1277    function mysql_add_existing_connection($dbh)
1278    {
1279        return MySQL::getInstance()->mysql_add_existing_connection($dbh);
1280    }
1281
1282    // http://www.php.net/manual/en/function.mysql-connect.php
1283    function mysql_connect($server, $username, $password, $new_link = false, $client_flags = false)
1284    {
1285        return MySQL::getInstance()->mysql_connect($server, $username, $password, $new_link, $client_flags);
1286    }
1287
1288    // http://www.php.net/manual/en/function.mysql-connect.php
1289    function mysql_pconnect($server, $username, $password, $new_link = false, $client_flags = false)
1290    {
1291        return MySQL::getInstance()->mysql_pconnect($server, $username, $password, $new_link, $client_flags);
1292    }
1293
1294    // http://www.php.net/manual/en/function.mysql-select-db.php
1295    function mysql_select_db($database_name, $link = false)
1296    {
1297        return MySQL::getInstance()->mysql_select_db($database_name, $link);
1298    }
1299
1300    function mysql_selectdb($database_name, $link = false)
1301    {
1302        return MySQL::getInstance()->mysql_select_db($database_name, $link);
1303    }
1304
1305    // http://www.php.net/manual/en/function.mysql-query.php
1306    function mysql_query($query, $link = false)
1307    {
1308        return MySQL::getInstance()->mysql_query($query, $link);
1309    }
1310
1311    // http://www.php.net/manual/en/function.mysql-real-escape-string.php
1312    function mysql_real_escape_string($string, $link = false)
1313    {
1314        return MySQL::getInstance()->mysql_real_escape_string($string, $link);
1315    }
1316
1317    // http://www.php.net/manual/en/function.mysql-escape-string.php
1318    function mysql_escape_string($string, $link = false)
1319    {
1320        return MySQL::getInstance()->mysql_escape_string($string, $link);
1321    }
1322
1323    // http://www.php.net/manual/en/function.mysql-fetch-array.php
1324    function mysql_fetch_array(&$result, $result_type = MYSQL_BOTH)
1325    {
1326        return MySQL::getInstance()->mysql_fetch_array($result, $result_type);
1327    }
1328
1329    // http://www.php.net/manual/en/function.mysql-fetch-assoc.php
1330    function mysql_fetch_assoc(&$result)
1331    {
1332        return MySQL::getInstance()->mysql_fetch_assoc($result);
1333    }
1334
1335    // http://www.php.net/manual/en/function.mysql-fetch-row.php
1336    function mysql_fetch_row(&$result)
1337    {
1338        return MySQL::getInstance()->mysql_fetch_row($result);
1339    }
1340
1341    // http://www.php.net/manual/en/function.mysql-fetch-object.php
1342    function mysql_fetch_object(&$result)
1343    {
1344        return MySQL::getInstance()->mysql_fetch_object($result);
1345    }
1346
1347    // http://www.php.net/manual/en/function.mysql-ping.php
1348    function mysql_ping($link = false)
1349    {
1350        return MySQL::getInstance()->mysql_ping($link);
1351    }
1352
1353    // http://www.php.net/manual/en/function.mysql-errno.php
1354    function mysql_errno($link = false)
1355    {
1356        return MySQL::getInstance()->mysql_errno($link);
1357    }
1358
1359    // http://www.php.net/manual/en/function.mysql-error.php
1360    function mysql_error($link = false)
1361    {
1362        return MySQL::getInstance()->mysql_error($link);
1363    }
1364
1365    // http://www.php.net/manual/en/function.mysql-affected-rows.php
1366    function mysql_affected_rows($link = false)
1367    {
1368        return MySQL::getInstance()->mysql_affected_rows($link);
1369    }
1370
1371    // http://www.php.net/manual/en/function.mysql-client-encoding.php
1372    function mysql_client_encoding($link = false)
1373    {
1374        return MySQL::getInstance()->mysql_client_encoding($link);
1375    }
1376
1377    // http://www.php.net/manual/en/function.mysql-close.php
1378    function mysql_close($link = false)
1379    {
1380        return MySQL::getInstance()->mysql_close($link);
1381    }
1382
1383    // http://www.php.net/manual/en/function.mysql-create-db.php
1384    function mysql_create_db($database_name, $link = false)
1385    {
1386        return MySQL::getInstance()->mysql_create_db($database_name, $link);
1387    }
1388
1389    function mysql_createdb($database_name, $link = false)
1390    {
1391        return MySQL::getInstance()->mysql_create_db($database_name, $link);
1392    }
1393
1394    // http://www.php.net/manual/en/function.mysql-data-seek.php
1395    function mysql_data_seek($result, $row_number)
1396    {
1397        return MySQL::getInstance()->mysql_data_seek($result, $row_number);
1398    }
1399
1400    // http://www.php.net/manual/en/function.mysql-list-dbs.php
1401    function mysql_list_dbs($link = false)
1402    {
1403        return MySQL::getInstance()->mysql_list_dbs($link);
1404    }
1405
1406    function mysql_listdbs($link = false)
1407    {
1408        return MySQL::getInstance()->mysql_list_dbs($link);
1409    }
1410
1411    // http://www.php.net/manual/en/function.mysql-db-name.php
1412    function mysql_db_name(&$result, $row, $field = 'Database')
1413    {
1414        return MySQL::getInstance()->mysql_db_name($result, $row, $field);
1415    }
1416
1417    function mysql_dbname(&$result, $row, $field = 'Database')
1418    {
1419        return MySQL::getInstance()->mysql_db_name($result, $row, $field);
1420    }
1421
1422    // http://www.php.net/manual/en/function.mysql-db-query.php
1423    function mysql_db_query($databaseName, $query, $link = false)
1424    {
1425        return MySQL::getInstance()->mysql_db_query($databaseName, $query, $link);
1426    }
1427
1428    // http://www.php.net/manual/en/function.mysql-drop-db.php
1429    function mysql_drop_db($databaseName, $link = false)
1430    {
1431        return MySQL::getInstance()->mysql_drop_db($databaseName, $link);
1432    }
1433
1434    function mysql_dropdb($databaseName, $link = false)
1435    {
1436        return MySQL::getInstance()->mysql_drop_db($databaseName, $link);
1437    }
1438
1439    // http://www.php.net/manual/en/function.mysql-unbuffered-query.php
1440    function mysql_unbuffered_query($query, $link = false)
1441    {
1442        return MySQL::getInstance()->mysql_unbuffered_query($query, $link);
1443    }
1444
1445    // http://www.php.net/manual/en/function.mysql-thread-id.php
1446    function mysql_thread_id($link = false)
1447    {
1448        return MySQL::getInstance()->mysql_thread_id($link);
1449    }
1450
1451    // http://www.php.net/manual/en/function.mysql-list-tables.php
1452    function mysql_list_tables($databaseName, $link = false)
1453    {
1454        return MySQL::getInstance()->mysql_list_tables($databaseName, $link);
1455    }
1456
1457    function mysql_listtables($databaseName, $link = false)
1458    {
1459        return MySQL::getInstance()->mysql_list_tables($databaseName, $link);
1460    }
1461
1462    // http://www.php.net/manual/en/function.mysql-tablename.php
1463    function mysql_tablename(&$result, $row)
1464    {
1465        return MySQL::getInstance()->mysql_tablename($result, $row);
1466    }
1467
1468    // http://www.php.net/manual/en/function.mysql-stat.php
1469    function mysql_stat($link = false)
1470    {
1471        return MySQL::getInstance()->mysql_stat($link);
1472    }
1473
1474    // http://www.php.net/manual/en/function.mysql-set-charset.php
1475    function mysql_set_charset($charset, $link = false)
1476    {
1477        return MySQL::getInstance()->mysql_set_charset($charset, $link);
1478    }
1479
1480    // http://www.php.net/manual/en/function.mysql-result.php
1481    function mysql_result(&$result, $rows, $field = false)
1482    {
1483        return MySQL::getInstance()->mysql_result($result, $rows, $field);
1484    }
1485
1486    // http://www.php.net/manual/en/function.mysql-list-processes.php
1487    function mysql_list_processes($link = false)
1488    {
1489        return MySQL::getInstance()->mysql_list_processes($link);
1490    }
1491
1492    // http://www.php.net/manual/en/function.mysql-insert-id.php
1493    function mysql_insert_id($link = false)
1494    {
1495        return MySQL::getInstance()->mysql_insert_id($link);
1496    }
1497
1498    // http://www.php.net/manual/en/function.mysql-get-server-info.php
1499    function mysql_get_server_info($link = false)
1500    {
1501        return MySQL::getInstance()->mysql_get_server_info($link);
1502    }
1503
1504    // http://www.php.net/manual/en/function.mysql-get-proto-info.php
1505    function mysql_get_proto_info($link = false)
1506    {
1507        return MySQL::getInstance()->mysql_get_proto_info($link);
1508    }
1509
1510    // http://www.php.net/manual/en/function.mysql-get-host-info.php
1511    function mysql_get_host_info($link = false)
1512    {
1513        return MySQL::getInstance()->mysql_get_host_info($link);
1514    }
1515
1516    // http://www.php.net/manual/en/function.mysql-get-client-info.php
1517    function mysql_get_client_info($link = false)
1518    {
1519        return MySQL::getInstance()->mysql_get_client_info($link);
1520    }
1521
1522    // http://www.php.net/manual/en/function.mysql-free-result.php
1523    function mysql_free_result(&$result)
1524    {
1525        return MySQL::getInstance()->mysql_free_result($result);
1526    }
1527
1528    function mysql_freeresult(&$result)
1529    {
1530        return MySQL::getInstance()->mysql_free_result($result);
1531    }
1532
1533    // http://www.php.net/manual/en/function.mysql-fetch-lengths.php
1534    function mysql_fetch_lengths(&$result)
1535    {
1536        return MySQL::getInstance()->mysql_fetch_lengths($result);
1537    }
1538
1539    // http://www.php.net/manual/en/function.mysql-list-fields.php
1540    function mysql_list_fields($databaseName, $tableName, $link = false)
1541    {
1542        return MySQL::getInstance()->mysql_list_fields($databaseName, $tableName, $link);
1543    }
1544
1545    function mysql_listfields($databaseName, $tableName, $link = false)
1546    {
1547        return MySQL::getInstance()->mysql_list_fields($databaseName, $tableName, $link);
1548    }
1549
1550    // http://www.php.net/manual/en/function.mysql-field-len.php
1551    function mysql_field_len(&$result, $fieldOffset = false)
1552    {
1553        return MySQL::getInstance()->mysql_field_len($result, $fieldOffset);
1554    }
1555
1556    function mysql_fieldlen(&$result, $fieldOffset = false)
1557    {
1558        return MySQL::getInstance()->mysql_field_len($result, $fieldOffset);
1559    }
1560
1561    // http://www.php.net/manual/en/function.mysql-field-flags.php
1562    function mysql_field_flags(&$result, $fieldOffset = false)
1563    {
1564        return MySQL::getInstance()->mysql_field_flags($result, $fieldOffset);
1565    }
1566
1567    function mysql_fieldflags(&$result, $fieldOffset = false)
1568    {
1569        return MySQL::getInstance()->mysql_field_flags($result, $fieldOffset);
1570    }
1571
1572    // http://www.php.net/manual/en/function.mysql-field-name.php
1573    function mysql_field_name(&$result, $fieldOffset = false)
1574    {
1575        return MySQL::getInstance()->mysql_field_name($result, $fieldOffset);
1576    }
1577
1578    function mysql_fieldname(&$result, $fieldOffset = false)
1579    {
1580        return MySQL::getInstance()->mysql_field_name($result, $fieldOffset);
1581    }
1582
1583    // http://www.php.net/manual/en/function.mysql-field-type.php
1584    function mysql_field_type(&$result, $fieldOffset = false)
1585    {
1586        return MySQL::getInstance()->mysql_field_type($result, $fieldOffset);
1587    }
1588
1589    function mysql_fieldtype(&$result, $fieldOffset = false)
1590    {
1591        return MySQL::getInstance()->mysql_field_type($result, $fieldOffset);
1592    }
1593
1594    // http://www.php.net/manual/en/function.mysql-field-table.php
1595    function mysql_field_table(&$result, $fieldOffset = false)
1596    {
1597        return MySQL::getInstance()->mysql_field_table($result, $fieldOffset);
1598    }
1599
1600    function mysql_fieldtable(&$result, $fieldOffset = false)
1601    {
1602        return MySQL::getInstance()->mysql_field_table($result, $fieldOffset);
1603    }
1604
1605    // http://www.php.net/manual/en/function.mysql-field-seek.php
1606    function mysql_field_seek(&$result, $fieldOffset = false)
1607    {
1608        return MySQL::getInstance()->mysql_field_seek($result, $fieldOffset);
1609    }
1610
1611    // http://www.php.net/manual/en/function.mysql-fetch-field.php
1612    function mysql_fetch_field(&$result, $fieldOffset = false)
1613    {
1614        return MySQL::getInstance()->mysql_fetch_field($result, $fieldOffset);
1615    }
1616
1617    // http://www.php.net/manual/en/function.mysql-num-fields.php
1618    function mysql_num_fields($result)
1619    {
1620        return MySQL::getInstance()->mysql_num_fields($result);
1621    }
1622
1623    function mysql_numfields($result)
1624    {
1625        return MySQL::getInstance()->mysql_num_fields($result);
1626    }
1627
1628    // http://www.php.net/manual/en/function.mysql-num-rows.php
1629    function mysql_num_rows($result)
1630    {
1631        return MySQL::getInstance()->mysql_num_rows($result);
1632    }
1633
1634    function mysql_numrows($result)
1635    {
1636        return MySQL::getInstance()->mysql_num_rows($result);
1637    }
1638
1639    // http://php.net/manual/en/function.mysql-info.php
1640    function mysql_info($link = false)
1641    {
1642        return MySQL::getInstance()->mysql_info($link);
1643    }
1644
1645    // Close all connections
1646    function mysql_close_all()
1647    {
1648        return MySQL::getInstance()->mysql_close_all();
1649    }
1650
1651    // is_resource function over ride
1652    function is_resource_custom($resource)
1653    {
1654        return MySQL::getInstance()->is_resource($resource);
1655    }
1656
1657    // get_resource_type_custom function over ride
1658    function get_resource_type_custom($resource)
1659    {
1660        return MySQL::getInstance()->get_resource_type($resource);
1661    }
1662
1663}
Note: See TracBrowser for help on using the repository browser.