includes/dbal.php
changeset 857 f3a5a276208c
parent 812 68060328e9c6
child 860 c931041e689a
equal deleted inserted replaced
856:0b7ff06aad13 857:f3a5a276208c
   129                       Most recent SQL query:</p>
   129                       Most recent SQL query:</p>
   130                       <pre>'.$bt.'</pre>';
   130                       <pre>'.$bt.'</pre>';
   131     return $internal_text;
   131     return $internal_text;
   132   }
   132   }
   133   
   133   
   134   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
   134   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
   135   {
   135   {
   136     if ( !defined('ENANO_SQL_CONSTANTS') )
   136     if ( !defined('ENANO_SQL_CONSTANTS') )
   137     {
   137     {
   138       define('ENANO_SQL_CONSTANTS', '');
   138       define('ENANO_SQL_CONSTANTS', '');
   139       define('ENANO_DBLAYER', 'MYSQL');
   139       define('ENANO_DBLAYER', 'MYSQL');
   151       }
   151       }
   152       else
   152       else
   153       {
   153       {
   154         @include(ENANO_ROOT.'/config.php');
   154         @include(ENANO_ROOT.'/config.php');
   155       }
   155       }
   156         
   156       
   157       if ( isset($crypto_key) )
   157       if ( isset($crypto_key) )
   158         unset($crypto_key); // Get this sucker out of memory fast
   158         unset($crypto_key); // Get this sucker out of memory fast
       
   159       if ( empty($dbport) )
       
   160         $dbport = 3306;
   159       
   161       
   160       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   162       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   161       {
   163       {
   162         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   164         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   163         if ( !defined('scriptPath') )
   165         if ( !defined('scriptPath') )
   186         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 0);
   188         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 0);
   187         exit;
   189         exit;
   188       }
   190       }
   189     }
   191     }
   190     
   192     
   191     $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd);
   193     if ( !$dbport )
       
   194       $dbport = 3306;
       
   195     
       
   196     if ( $dbhost && !empty($dbport) && $dbport != 3306 )
       
   197       $dbhost = '127.0.0.1';
       
   198     
       
   199     $host_line = ( preg_match('/^:/', $dbhost) ) ? $dbhost : "{$dbhost}:{$dbport}";
       
   200     
       
   201     $this->_conn = @mysql_connect($host_line, $dbuser, $dbpasswd);
   192     unset($dbuser);
   202     unset($dbuser);
   193     unset($dbpasswd); // Security
   203     unset($dbpasswd); // Security
   194     
   204     
   195     if ( !$this->_conn && !$manual_credentials )
   205     if ( !$this->_conn && !$manual_credentials )
   196     {
   206     {
   837                       Most recent SQL query:</p>
   847                       Most recent SQL query:</p>
   838                       <pre>'.$bt.'</pre>';
   848                       <pre>'.$bt.'</pre>';
   839     return $internal_text;
   849     return $internal_text;
   840   }
   850   }
   841   
   851   
   842   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false)
   852   function connect($manual_credentials = false, $dbhost = false, $dbuser = false, $dbpasswd = false, $dbname = false, $dbport = false)
   843   {
   853   {
   844     if ( !defined('ENANO_SQL_CONSTANTS') )
   854     if ( !defined('ENANO_SQL_CONSTANTS') )
   845     {
   855     {
   846       define('ENANO_SQL_CONSTANTS', '');
   856       define('ENANO_SQL_CONSTANTS', '');
   847       define('ENANO_DBLAYER', 'PGSQL');
   857       define('ENANO_DBLAYER', 'PGSQL');
   862         @include(ENANO_ROOT.'/config.php');
   872         @include(ENANO_ROOT.'/config.php');
   863       }
   873       }
   864         
   874         
   865       if ( isset($crypto_key) )
   875       if ( isset($crypto_key) )
   866         unset($crypto_key); // Get this sucker out of memory fast
   876         unset($crypto_key); // Get this sucker out of memory fast
       
   877       if ( empty($dbport) )
       
   878         $dbport = 5432;
   867       
   879       
   868       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   880       if ( !defined('ENANO_INSTALLED') && !defined('MIDGET_INSTALLED') && !defined('IN_ENANO_INSTALL') )
   869       {
   881       {
   870         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   882         // scriptPath isn't set yet - we need to autodetect it to avoid infinite redirects
   871         if ( !defined('scriptPath') )
   883         if ( !defined('scriptPath') )
   888         // header("Location: $loc");
   900         // header("Location: $loc");
   889         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
   901         redirect($loc, 'Enano not installed', 'We can\'t seem to find an Enano installation (valid config file). You will be transferred to the installation wizard momentarily...', 3);
   890         exit;
   902         exit;
   891       }
   903       }
   892     }
   904     }
   893     $this->_conn = @pg_connect("host=$dbhost port=5432 dbname=$dbname user=$dbuser password=$dbpasswd");
   905     
       
   906     if ( empty($dbport) )
       
   907       $dbport = 5432;
       
   908     
       
   909     $this->_conn = @pg_connect("host=$dbhost port=$dbport dbname=$dbname user=$dbuser password=$dbpasswd");
   894     unset($dbuser);
   910     unset($dbuser);
   895     unset($dbpasswd); // Security
   911     unset($dbpasswd); // Security
   896     
   912     
   897     if ( !$this->_conn && !$manual_credentials )
   913     if ( !$this->_conn && !$manual_credentials )
   898     {
   914     {
   949       $this->report_query($q);
   965       $this->report_query($q);
   950       grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
   966       grinding_halt('SQL Injection attempt', '<p>Enano has caught and prevented an SQL injection attempt. Your IP address has been recorded and the administrator has been notified.</p><p>Query was:</p><pre>'.htmlspecialchars($q).'</pre>');
   951     }
   967     }
   952     
   968     
   953     $time_start = microtime_float();
   969     $time_start = microtime_float();
   954     $r = pg_query($q);
   970     $r = @pg_query($q);
   955     $this->query_times[$q] = microtime_float() - $time_start;
   971     $this->query_times[$q] = microtime_float() - $time_start;
   956     $this->latest_result = $r;
   972     $this->latest_result = $r;
   957     return $r;
   973     return $r;
   958   }
   974   }
   959   
   975