objSQL Database Connection Instance
To connect to a database, create an objSQL() instance.
- 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: mysql, pgsql, sqlite3 or sqlsrv. Enter mysql as the driver for MariaDB.
- objSQL performs an internal validation before it attempts to connect to a database by verifying the database type. A failure triggers an error.
Returns: Connection resource/object or false on failure.
- Call obj_close() to close the current connection instance.
Returns: True on success or false on failure.
<?php
/**
Drivers
MySQL/MariaDB: mysql
Postgres: pgsql
SQLite3: sqlite3
SQL Server: sqlsrv
usage: str - $connection = "dbtype,localhost,username,password,database,port";
usage: array - $connection = array( "dbtype","localhost","username","password","database","port" );
*/
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();
}
?>