Opens a new connection to a named database server.
mixed objSQL ( str driver, str host, str user, str pass, str database[, int port ] )
Arraymixed objSQL ( array ( str driver, str host, str user, str pass, str database[, int port ] ) )
Connection resource or object.
<?php
/**
Drivers
CUBRID: cubrid or pdo:cubrid
Firebird: firebird or pdo:firebird
MySQL/MariaDB: mysql or pdo:mysql
Oracle: oracle or pdo:oracle
Postgres: pgsql or pdo:pgsql
SQLite3: sqlite3 or pdo:sqlite3
SQL Server: sqlsrv or pdo:sqlsrv
*/
try
{
$dbh = new objSQL( "mysql,localhost,root,pass,mydb,3306" );
if ( error_get_last() !== null )
throw new Exception( error_get_last()['message'] );
//Query block
$dbh->obj_close();
}
catch ( Exception $e )
{
echo $e->getMessage();
}
try
{
$dbh = new objSQL( array( "pdo:mysql","localhost","root","pass","mydb",3306 ) );
if ( error_get_last() !== null )
throw new Exception( error_get_last()['message'] );
//Query block
$dbh->obj_close();
}
catch ( Exception $e )
{
echo $e->getMessage();
}
?>
See also: obj_close