Example #1
0
 /**
  * Initializes a database connection.
  * It returns the connection, if successful.
  *
  * @param string $db_server
  * @param string $db_name
  * @param string $db_user
  * @param string $db_passwd
  * @param string $db_prefix
  * @param array $db_options
  *
  * @return resource
  */
 static function initiate($db_server, $db_name, $db_user, $db_passwd, $db_prefix, $db_options = array())
 {
     global $db_in_transact, $sqlite_error;
     if (substr($db_name, -3) != '.db') {
         $db_name .= '.db';
     }
     // initialize the instance... if not done already!
     if (self::$_db === null) {
         self::$_db = new self();
     }
     if (!empty($db_options['persist'])) {
         $connection = @sqlite_popen($db_name, 0666, $sqlite_error);
     } else {
         $connection = @sqlite_open($db_name, 0666, $sqlite_error);
     }
     // Something's wrong, show an error if its fatal (which we assume it is)
     if (!$connection) {
         if (!empty($db_options['non_fatal'])) {
             return null;
         } else {
             display_db_error();
         }
     }
     $db_in_transact = false;
     // This is frankly stupid - stop SQLite returning alias names!
     @sqlite_query('PRAGMA short_column_names = 1', $connection);
     // Make some user defined functions!
     sqlite_create_function($connection, 'unix_timestamp', 'elk_udf_unix_timestamp', 0);
     sqlite_create_function($connection, 'inet_aton', 'elk_udf_inet_aton', 1);
     sqlite_create_function($connection, 'inet_ntoa', 'elk_udf_inet_ntoa', 1);
     sqlite_create_function($connection, 'find_in_set', 'elk_udf_find_in_set', 2);
     sqlite_create_function($connection, 'year', 'elk_udf_year', 1);
     sqlite_create_function($connection, 'month', 'elk_udf_month', 1);
     sqlite_create_function($connection, 'dayofmonth', 'elk_udf_dayofmonth', 1);
     sqlite_create_function($connection, 'concat', 'elk_udf_concat');
     sqlite_create_function($connection, 'locate', 'elk_udf_locate', 2);
     sqlite_create_function($connection, 'regexp', 'elk_udf_regexp', 2);
     return $connection;
 }