includes/dbal.php
changeset 348 87e08a6e4fec
parent 331 03850e101d7f
child 352 9d7225c0db6d
equal deleted inserted replaced
347:299a90e28abc 348:87e08a6e4fec
   161           $sp = dirname($_SERVER['REQUEST_URI']);
   161           $sp = dirname($_SERVER['REQUEST_URI']);
   162           if($sp == '/' || $sp == '\\') $sp = '';
   162           if($sp == '/' || $sp == '\\') $sp = '';
   163           define('scriptPath', $sp);
   163           define('scriptPath', $sp);
   164           define('contentPath', "$sp/index.php?title=");
   164           define('contentPath', "$sp/index.php?title=");
   165         }
   165         }
   166         $loc = scriptPath . '/install.php';
   166         $loc = scriptPath . '/install/index.php';
   167         define('IN_ENANO_INSTALL', 1);
   167         define('IN_ENANO_INSTALL', 1);
   168         $GLOBALS['lang'] = new Language('eng');
   168         $GLOBALS['lang'] = new Language('eng');
   169         global $lang;
   169         global $lang;
   170         $lang->load_file('./language/english/enano.json');
   170         $lang->load_file('./language/english/core.json');
   171         $lang->load_file('./language/english/install.json');
   171         $lang->load_file('./language/english/install.json');
   172         // header("Location: $loc");
   172         // header("Location: $loc");
   173         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);
   173         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);
   174         exit;
   174         exit;
   175       }
   175       }
   176     }
   176     }
   177     
   177     
   178     $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd);
   178     $this->_conn = @mysql_connect($dbhost, $dbuser, $dbpasswd);
   179     unset($dbuser);
   179     unset($dbuser);
   180     unset($dbpasswd); // Security
   180     unset($dbpasswd); // Security
   181     
   181     
   182     if ( !$this->_conn )
   182     if ( !$this->_conn && !$manual_credentials )
   183     {
   183     {
   184       grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
   184       grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to MySQL.<br />'.mysql_error().'</p>');
       
   185     }
       
   186     else if ( !$this->_conn && $manual_credentials )
       
   187     {
       
   188       return false;
   185     }
   189     }
   186     
   190     
   187     // Reset some variables
   191     // Reset some variables
   188     $this->query_backtrace = array();
   192     $this->query_backtrace = array();
   189     $this->query_times = array();
   193     $this->query_times = array();
   675 		return $this->sql_version;
   679 		return $this->sql_version;
   676 	}
   680 	}
   677 
   681 
   678 	function sql_error()
   682 	function sql_error()
   679 	{
   683 	{
   680 		if ( $this->_conn )
   684     return mysql_error();
   681 		{
       
   682 			return mysql_error();
       
   683 		}
       
   684 		else
       
   685 		{
       
   686 			return array();
       
   687 		}
       
   688 	}
   685 	}
   689   function sql_escape_string($t) 
   686   function sql_escape_string($t) 
   690   {
   687   {
   691     return mysql_real_escape_string($t);
   688     return mysql_real_escape_string($t);
   692   }
   689   }
   863     $t = "{'mode':'error','error':'An error occurred during database query.\nQuery was:\n  $q\n\nError returned by PostgreSQL: $e'}";
   860     $t = "{'mode':'error','error':'An error occurred during database query.\nQuery was:\n  $q\n\nError returned by PostgreSQL: $e'}";
   864     die($t);
   861     die($t);
   865   }
   862   }
   866   
   863   
   867   function get_error($t = '') {
   864   function get_error($t = '') {
   868     header('HTTP/1.1 500 Internal Server Error');
   865     @header('HTTP/1.1 500 Internal Server Error');
   869     $bt = $this->sql_backtrace();
   866     $bt = $this->sql_backtrace();
   870     $e = htmlspecialchars(pg_last_error());
   867     $e = htmlspecialchars(pg_last_error());
   871     if($e=='') $e='&lt;none&gt;';
   868     if($e=='') $e='&lt;none&gt;';
   872     global $email;
   869     global $email;
   873     $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) ) ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;' : '';
   870     $email_info = ( defined('ENANO_CONFIG_FETCHED') && is_object($email) ) ? ', at &lt;' . $email->jscode() . $email->encryptEmail(getConfig('contact_email')) . '&gt;' : '';
   931     }
   928     }
   932     $this->_conn = @pg_connect("host=$dbhost port=5432 dbname=$dbname user=$dbuser password=$dbpasswd");
   929     $this->_conn = @pg_connect("host=$dbhost port=5432 dbname=$dbname user=$dbuser password=$dbpasswd");
   933     unset($dbuser);
   930     unset($dbuser);
   934     unset($dbpasswd); // Security
   931     unset($dbpasswd); // Security
   935     
   932     
   936     if ( !$this->_conn )
   933     if ( !$this->_conn && !$manual_credentials )
   937     {
   934     {
   938       grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to PostgreSQL.<br />'.pg_last_error().'</p>');
   935       grinding_halt('Enano is having a problem', '<p>Error: couldn\'t connect to PostgreSQL.<br />'.pg_last_error().'</p>');
       
   936     }
       
   937     else if ( !$this->_conn && $manual_credentials )
       
   938     {
       
   939       return false;
   939     }
   940     }
   940     
   941     
   941     // Reset some variables
   942     // Reset some variables
   942     $this->query_backtrace = array();
   943     $this->query_backtrace = array();
   943     $this->query_times = array();
   944     $this->query_times = array();
  1423 
  1424 
  1424 	function sql_error()
  1425 	function sql_error()
  1425 	{
  1426 	{
  1426 		if ( $this->_conn )
  1427 		if ( $this->_conn )
  1427 		{
  1428 		{
  1428 			return mysql_error();
  1429 			return pg_last_error();
  1429 		}
  1430 		}
  1430 		else
  1431 		else
  1431 		{
  1432 		{
  1432 			return array();
  1433 			return ( defined('IN_ENANO_INSTALL') ) ? $GLOBALS["lang"]->get('dbpgsql_msg_err_auth') : 'Access to the database was denied. Ensure that your database exists and that your username and password are correct.';
  1433 		}
  1434 		}
  1434 	}
  1435 	}
  1435   function sql_escape_string($t) 
  1436   function sql_escape_string($t) 
  1436   {
  1437   {
  1437     return mysql_real_escape_string($t);
  1438     return mysql_real_escape_string($t);