Ejemplo n.º 1
0
 public function connect($config = array())
 {
     $this->config = $config;
     $this->connect = $this->config['pconnect'] === true ? @fbsql_pconnect($this->config['host'], $this->config['user'], $this->config['password']) : @fbsql_connect($this->config['host'], $this->config['user'], $this->config['password']);
     if (empty($this->connect)) {
         die(getErrorMessage('Database', 'mysqlConnectError'));
     }
     fbsql_select_db($this->config['database'], $this->connect);
 }
 function SelectDB($dbName)
 {
     $this->databaseName = $dbName;
     if ($this->_connectionID) {
         return @fbsql_select_db($dbName, $this->_connectionID);
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
Archivo: fbsql.php Proyecto: roojs/pear
 /**
  * Connect to the database server, log in and open the database
  *
  * Don't call this method directly.  Use DB::connect() instead.
  *
  * @param array $dsn         the data source name
  * @param bool  $persistent  should the connection be persistent?
  *
  * @return int  DB_OK on success. A DB_Error object on failure.
  */
 function connect($dsn, $persistent = false)
 {
     if (!PEAR::loadExtension('fbsql')) {
         return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
     }
     $this->dsn = $dsn;
     if ($dsn['dbsyntax']) {
         $this->dbsyntax = $dsn['dbsyntax'];
     }
     $params = array($dsn['hostspec'] ? $dsn['hostspec'] : 'localhost', $dsn['username'] ? $dsn['username'] : null, $dsn['password'] ? $dsn['password'] : null);
     $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect';
     $ini = ini_get('track_errors');
     $php_errormsg = '';
     if ($ini) {
         $this->connection = @call_user_func_array($connect_function, $params);
     } else {
         @ini_set('track_errors', 1);
         $this->connection = @call_user_func_array($connect_function, $params);
         @ini_set('track_errors', $ini);
     }
     if (!$this->connection) {
         return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg);
     }
     if ($dsn['database']) {
         if (!@fbsql_select_db($dsn['database'], $this->connection)) {
             return $this->fbsqlRaiseError();
         }
     }
     return DB_OK;
 }
Ejemplo n.º 4
0
 /**
  * Connect to a database and log in as the specified user.
  *
  * @param $dsn the data source name (see DB::parseDSN for syntax)
  * @param $persistent (optional) whether the connection should
  *        be persistent
  * @access public
  * @return int DB_OK on success, a DB error on failure
  */
 function connect($dsninfo, $persistent = false)
 {
     if (!DB::assertExtension('fbsql')) {
         return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
     }
     $this->dsn = $dsninfo;
     $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
     $php_errormsg = '';
     $connect_function = $persistent ? 'fbsql_pconnect' : 'fbsql_connect';
     if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
         $conn = @$connect_function($dbhost, $dsninfo['username'], $dsninfo['password']);
     } elseif ($dbhost && $dsninfo['username']) {
         $conn = @$connect_function($dbhost, $dsninfo['username']);
     } elseif ($dbhost) {
         $conn = @$connect_function($dbhost);
     } else {
         $conn = false;
     }
     if (!$conn) {
         if (empty($php_errormsg)) {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED);
         } else {
             return $this->raiseError(DB_ERROR_CONNECT_FAILED, null, null, null, $php_errormsg);
         }
     }
     if ($dsninfo['database']) {
         if (!fbsql_select_db($dsninfo['database'], $conn)) {
             return $this->fbsqlRaiseError();
         }
     }
     $this->connection = $conn;
     return DB_OK;
 }
 /**
  * Send a query to the database and return any results
  *
  * @access public
  *
  * @param string  $query  the SQL query
  * @param mixed   $types  array that contains the types of the columns in
  *                        the result set
  *
  * @return mixed a result handle or MDB_OK on success, a MDB error on failure
  */
 function query($query, $types = NULL)
 {
     $this->debug("Query: {$query}");
     $ismanip = MDB::isManip($query);
     $this->last_query = $query;
     $first = $this->first_selected_row;
     $limit = $this->selected_row_limit;
     $this->first_selected_row = $this->selected_row_limit = 0;
     $result = $this->connect();
     if (MDB::isError($result)) {
         return $result;
     }
     if ($limit > 0) {
         if (!$ismanip) {
             $query = str_replace('SELECT', "SELECT TOP({$first},{$limit})", $query);
         }
     }
     if ($this->database_name != '') {
         if (!@fbsql_select_db($this->database_name, $this->connection)) {
             return $this->fbsqlRaiseError();
         }
     }
     // Add ; to the end of the query. This is required by FrontBase
     $query .= ';';
     if ($result = @fbsql_query($query, $this->connection)) {
         if ($ismanip) {
             $this->affected_rows = @fbsql_affected_rows($this->connection);
             return MDB_OK;
         } else {
             $result_value = intval($result);
             $this->highest_fetched_row[$result_value] = -1;
             if ($types != NULL) {
                 if (!is_array($types)) {
                     $types = array($types);
                 }
                 if (MDB::isError($err = $this->setResultTypes($result, $types))) {
                     $this->freeResult($result);
                     return $err;
                 }
             }
             return $result;
         }
     }
     return $this->fbsqlRaiseError();
 }
Ejemplo n.º 6
0
 function connect_fbql($host, $user, $pass, $db)
 {
     $this->fbsql_link = fbsql_pconnect($host, $user, $pass);
     if ($this->fbsql_link == 0) {
         return false;
     }
     if (!fbsql_select_db($db, $this->fbsql_link)) {
         print "Database Error " . msql_error() . "\n";
         return false;
     }
     return $this->fbsql_link;
 }
Ejemplo n.º 7
0
 /**
  * Execute a query
  * @param string $query  query
  * @param boolean $is_manip  if the query is a manipulation query
  * @param resource $connection
  * @param string $database_name
  * @return result or error object
  * @access protected
  */
 function &_doQuery($query, $is_manip = false, $connection = null, $database_name = null)
 {
     $this->last_query = $query;
     $result = $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'pre'));
     if ($result) {
         if (MDB2::isError($result)) {
             return $result;
         }
         $query = $result;
     }
     if ($this->options['disable_query']) {
         $result = $is_manip ? 0 : null;
         return $result;
     }
     if (null === $connection) {
         $connection = $this->getConnection();
         if (MDB2::isError($connection)) {
             return $connection;
         }
     }
     if (null === $database_name) {
         $database_name = $this->database_name;
     }
     if ($database_name) {
         if ($database_name != $this->connected_database_name) {
             if (!@fbsql_select_db($database_name, $connection)) {
                 $err = $this->raiseError(null, null, null, 'Could not select the database: ' . $database_name, __FUNCTION__);
                 return $err;
             }
             $this->connected_database_name = $database_name;
         }
     }
     $result = @fbsql_query($query, $connection);
     if (!$result) {
         $err =& $this->raiseError(null, null, null, 'Could not execute statement', __FUNCTION__);
         return $err;
     }
     $this->debug($query, 'query', array('is_manip' => $is_manip, 'when' => 'post', 'result' => $result));
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Execute a query
  * @param string $query  query
  * @param boolean $is_manip  if the query is a manipulation query
  * @param resource $connection
  * @param string $database_name
  * @return result or error object
  * @access protected
  */
 function _doQuery($query, $is_manip = false, $connection = null, $database_name = null)
 {
     $this->last_query = $query;
     $this->debug($query, 'query', $is_manip);
     if ($this->options['disable_query']) {
         if ($is_manip) {
             return 0;
         }
         return null;
     }
     if (is_null($connection)) {
         $connection = $this->getConnection();
         if (PEAR::isError($connection)) {
             return $connection;
         }
     }
     if (is_null($database_name)) {
         $database_name = $this->database_name;
     }
     if ($database_name) {
         if ($database_name != $this->connected_database_name) {
             if (!@fbsql_select_db($database_name, $connection)) {
                 return $this->raiseError();
             }
             $this->connected_database_name = $database_name;
         }
     }
     $result = @fbsql_query($query, $connection);
     if (!$result) {
         return $this->raiseError();
     }
     return $result;
 }