/**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     // if (!isset(self::$connection)) {
     // Load configuration as an array. Use the actual location of your configuration file
     //    self::$connection = new mysqli('localhost', 'root', 'root', 'servicioslegales');
     //  }
     self::$connection = mysqli_init();
     if (!self::$connection) {
         die('mysqli_init failed');
     }
     if (!self::$connection->options(MYSQLI_INIT_COMMAND, 'SET AUTOCOMMIT = 0')) {
         die('Setting MYSQLI_INIT_COMMAND failed');
     }
     if (!self::$connection->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5)) {
         die('Setting MYSQLI_OPT_CONNECT_TIMEOUT failed');
     }
     if (!self::$connection->real_connect('localhost', 'root', 'root', 'servicioslegales')) {
         die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 2
0
 public static function closeConnection()
 {
     self::$connection = null;
     return true;
 }