mirror of
https://gitlab.com/CodeSolutionsProject/DBWrapper.git
synced 2026-02-15 17:41:32 +01:00
Update dbwrapper.php. Fix Throw
This commit is contained in:
@@ -12,19 +12,19 @@ function dbw_connect($tdb,$server,$database=NULL,$user = NULL,$password=NULL){
|
|||||||
switch ($tdb){
|
switch ($tdb){
|
||||||
case "mysql":
|
case "mysql":
|
||||||
case "mysqli":
|
case "mysqli":
|
||||||
$return[0] = mysqli_connect($server,$user,$password,$database) or throw new Exception('Database connection error');
|
$return[0] = mysqli_connect($server,$user,$password,$database) or throwExceptionDBConn();
|
||||||
$return[1] = "mysqli"; //Return standard mysqli for other funcs.
|
$return[1] = "mysqli"; //Return standard mysqli for other funcs.
|
||||||
break;
|
break;
|
||||||
case "sqlite":
|
case "sqlite":
|
||||||
case "sqlite3":
|
case "sqlite3":
|
||||||
$return[0] = new SQLite3($server);
|
$return[0] = new SQLite3($server);
|
||||||
if (!$return[0]) throw new Exception('Database connection error');
|
if (!$return[0]) throwExceptionDBConn();
|
||||||
$return[1] = "sqlite"; //Return standard SQLite3 for other funcs.
|
$return[1] = "sqlite"; //Return standard SQLite3 for other funcs.
|
||||||
break;
|
break;
|
||||||
case "PostgreSQL":
|
case "PostgreSQL":
|
||||||
case "pg":
|
case "pg":
|
||||||
case "PgSQL":
|
case "PgSQL":
|
||||||
$return[0] = pg_connect("host=$server dbname=$database user=$user password=$password") or throw new Exception('Database connection error. ' . pg_last_error());
|
$return[0] = pg_connect("host=$server dbname=$database user=$user password=$password") or throwExceptionDBConn();
|
||||||
$return[1] = "PgSQL"; //Return standard PgSQL for other funcs.
|
$return[1] = "PgSQL"; //Return standard PgSQL for other funcs.
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -34,6 +34,10 @@ function dbw_connect($tdb,$server,$database=NULL,$user = NULL,$password=NULL){
|
|||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function throwExceptionDBConn() {
|
||||||
|
throw new Exception('Database connection error');
|
||||||
|
}
|
||||||
|
|
||||||
/** Escapes conflictive chars for inserting into database */
|
/** Escapes conflictive chars for inserting into database */
|
||||||
function dbw_escape_string($conn,$string){
|
function dbw_escape_string($conn,$string){
|
||||||
switch ($conn[1]){
|
switch ($conn[1]){
|
||||||
|
|||||||
Reference in New Issue
Block a user