Project Pages

PHP Classes
SourceForge
Downloads
Archived Documentation

DB Connection Methods

objSQL
obj_close

Error Handling Methods

obj_error
obj_error_message

Statement Methods

obj_delete
obj_insert
obj_paging
obj_query
obj_select
obj_update

Statement Argument Methods

obj_batch_data
obj_cols
obj_data
obj_limit
obj_offset
obj_order_by
obj_sort_order
obj_table
obj_where

Resultset Methods

obj_affected_rows
obj_fetch_assoc
obj_fetch_num
obj_fetch_object
obj_field
obj_free_result
obj_num_fields
obj_num_rows

Prepared Statement Methods

obj_bind
obj_close_statement
obj_execute
obj_free_statement
obj_prepare_statement

Transaction Methods

obj_commit
obj_rollback
obj_savepoint
obj_transaction

Utility Methods

obj_escape
obj_info
obj_row_count


objSQL()

Opens a new connection to a named database server.

  • The database connection information can be entered as a comma delimited string or an array.
  • Database types are case-insensitive but must be entered as: cubrid, firebird, mariadb, mysql, oracle, pgsql, sqlite or sqlsrv. You can enter mariadb or mysql for the MariaDB driver.
  • Firebird does not allow you to change the default port.
  • objSQL performs an internal validation before it attempts to connect to a database by verifying the database type and available PHP extension. A failure triggers an exception.
  • objSQL will first attempt to load PDO drivers if available. If not, it loads drivers for the standard extension.


Parameters:

Comma delimited string
mixed objSQL ( str driver, str host, str user, str pass, str database[, int port ] )

Array
mixed objSQL ( array ( str driver, str host, str user, str pass, str database[, int port ] ) )

Returns:

Connection resource or object.


Example:

<?php  

/**  

PHP 5.4/5.5 Drivers  

CUBRID: cubrid 
Firebird: firebird 
MariaDB: mariadb or mysql  
MySQL: mysql 
Oracle: oracle 
Postgres: pgsql 
SQLite3: sqlite 
SQL Server: sqlsrv 

PHP 5.6 Drivers  

CUBRID: cubrid 
Firebird: firebird 
MariaDB: mariadb or mysql  
MySQL: mysql 
Oracle: oracle 
Postgres: pgsql 
SQLite3: sqlite 
SQL Server: sqlsrv 

PHP 7 Drivers  

Firebird: firebird 
MariaDB: mariadb or mysql  
MySQL: mysql 
Oracle: oracle 
Postgres: pgsql 
SQLite3: sqlite 
SQL Server: sqlsrv 

*/  

try  
{  
    
$dbh = new objSQL"mysql,localhost,root,pass,mydb,3306" );  
          
    if ( 
error_get_last() !== null )  
        throw new 
Exceptionerror_get_last()['message'] );  
          
    
//Query block    
      
    
$dbh->obj_close();      
}  
catch ( 
Exception $e )   
{  
    echo 
$e->getMessage();  
}  


try  
{  
    
$dbh = new objSQL( array( "mysql","localhost","root","pass","mydb",3306 ) );  
          
    if ( 
error_get_last() !== null )  
        throw new 
Exceptionerror_get_last()['message'] );  
          
    
//Query block    
      
    
$dbh->obj_close();      
}  
catch ( 
Exception $e )   
{  
    echo 
$e->getMessage();  
}  

?>

See also: obj_close