Пример #1
0
 public function __construct()
 {
     $cls = debug_backtrace();
     if (isset($cls[1]['class']) && $cls[1]['class'] == '\\lib\\sql') {
         $this->cls = $cls[1]['object'];
     }
     self::$db_name = self::$db_name ? self::$db_name : db_name;
     self::$db_user = self::$db_user ? self::$db_user : db_user;
     self::$db_pass = self::$db_pass ? self::$db_pass : db_pass;
     // self::$db_host = self::$db_host ? self::$db_host : db_host;
     if (!isset(self::$dbConnection[self::$db_name])) {
         // if mysqli class does not exist or have some problem show related error
         if (!class_exists('mysqli')) {
             echo "<p>" . T_("we can't find database service!") . " " . T_("please contact administrator!") . "</p>";
             exit;
         }
         self::$connection = @new \mysqli(self::$db_host, self::$db_user, self::$db_pass, self::$db_name);
         if (self::$connection->connect_errno == 0) {
             self::$connection->set_charset(self::$db_charset);
             self::$dbConnection[self::$db_name] = self::$connection;
         } else {
             if (self::$connection->connect_errno == 1045) {
                 echo "<p>" . T_("We can't connect to database service!") . " " . T_("Please contact administrator!") . "</p>";
                 exit;
             } else {
                 if (self::$connection->connect_errno == 1049) {
                     echo "<p>" . T_("We can't connect to correct database!") . " " . T_("Please contact administrator!") . "</p>";
                     exit;
                 } else {
                     $this->error(self::$connection->connect_error, self::$connection->connect_errno);
                 }
             }
         }
     }
 }
Пример #2
0
 public function __construct()
 {
     $cls = debug_backtrace();
     if (isset($cls[1]['class']) && $cls[1]['class'] == '\\lib\\sql') {
         $this->cls = $cls[1]['object'];
     }
     self::$db_name = self::$db_name ? self::$db_name : db_name;
     self::$db_user = self::$db_user ? self::$db_user : db_user;
     self::$db_pass = self::$db_pass ? self::$db_pass : db_pass;
     // self::$db_host = self::$db_host ? self::$db_host : db_host;
     if (!isset(self::$dbConnection[self::$db_name])) {
         // if mysqli class does not exist or have some problem show related error
         if (!class_exists('mysqli')) {
             echo "<p>" . T_("we can't find database service!") . " " . T_("please contact administrator!") . "</p>";
             \lib\main::$controller->_processor(array('force_stop' => true));
         }
         self::$connection = @new \mysqli(self::$db_host, self::$db_user, self::$db_pass, self::$db_name);
         if (self::$connection->connect_errno == 0) {
             self::$connection->set_charset(self::$db_charset);
             self::$dbConnection[self::$db_name] = self::$connection;
         } else {
             if (self::$connection->connect_errno == 1045) {
                 echo "<p>" . T_("We can't connect to database service!") . " " . T_("Please contact administrator!") . "</p>";
                 \lib\main::$controller->_processor(['force_stop' => true]);
             } else {
                 if (self::$connection->connect_errno == 1049) {
                     // database does not exist, go to install page
                     // echo( "<p>".T_("We can't connect to correct database!")." " .T_("Please contact administrator!")."</p>" );
                     // if method exist, used for forms
                     if (method_exists(\lib\main::$controller, 'redirector')) {
                         \lib\main::$controller->redirector()->set_domain()->set_url('cp/install?time=first_time');
                         \lib\main::$controller->_processor(['force_stop' => true, 'force_json' => true]);
                     } else {
                         $redirector = new \lib\redirector();
                         $redirector->set_domain()->set_url('cp/install?time=first_time')->redirect();
                     }
                 } else {
                     $this->error(self::$connection->connect_error, self::$connection->connect_errno);
                 }
             }
         }
     }
 }