]> CyberLeo.Net >> Repos - Github/YOURLS.git/blob - includes/ezSQL/ez_sql_pdo_yourls.php
Introduce yourls_sanitize_url_safe()
[Github/YOURLS.git] / includes / ezSQL / ez_sql_pdo_yourls.php
1 <?php
2
3 class ezSQL_pdo_YOURLS extends ezSQL_pdo {
4
5         /**
6         * Constructor - Overwrite original to use MySQL and handle custom port
7         * 
8         * @since 1.7
9         */
10         function __construct( $dbuser='', $dbpassword='', $dbname='', $dbhost='localhost', $encoding='' ) {
11         $this->show_errors = defined( 'YOURLS_DEBUG' ) && YOURLS_DEBUG; // comply to YOURLS debug mode
12                 $this->dbuser = $dbuser;
13                 $this->dbpassword = $dbpassword;
14                 $this->dbname = $dbname;
15                 // Get custom port if any
16                 if ( false !== strpos( $dbhost, ':' ) ) {
17                         list( $dbhost, $dbport ) = explode( ':', $dbhost );
18                         $dbhost = sprintf( '%1$s;port=%2$d', $dbhost, $dbport );
19                 }
20                 $this->dbhost = $dbhost;
21                 $this->encoding = $encoding;
22                 $dsn = 'mysql:host=' . $dbhost . ';dbname=' . $dbname ;
23                 $this->dsn = $dsn;
24                 
25                 // Turn on track errors 
26                 ini_set('track_errors',1);
27                 
28                 $this->connect( $dsn, $dbuser, $dbpassword );
29                 
30         }
31
32         /**
33          * Return MySQL server version
34          *
35          * @since 1.7
36          */
37         function mysql_version() {
38                 return ( $this->dbh->getAttribute(PDO::ATTR_SERVER_VERSION) );
39         }
40         
41         /**
42          * Perform mySQL query
43          *
44          * Added to the original function: logging of all queries
45          *
46          * @since 1.7
47          */
48         function query( $query ) {
49         
50                 // Keep history of all queries
51                 $this->debug_log[] = $query;
52
53                 // Original function
54                 return parent::query( $query );
55         }
56
57         /**
58         * Disconnect
59         * 
60         * Actually not needed for PDO it seems, the function is there only for consistency with
61         * other classes
62         *
63         * @since 1.7
64         */
65         function disconnect() {
66                 // bleh
67         }       
68         
69
70 }
71