mirror of
https://gitlab.com/CodeSolutionsProject/DBWrapper.git
synced 2026-02-14 17:11:33 +01:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d366ae0f1f | |||
| 3ee9010bee | |||
| 7dd89fd33f | |||
| 55db830eac |
@@ -1,4 +1,4 @@
|
||||
# DBWrapper - Version 1.4.2
|
||||
# DBWrapper - Version 1.5.0
|
||||
|
||||
This script is a simple wrapper for SQLite3, MySQL and PgSQL, for make possible to use different BD systems without changing the functions.
|
||||
|
||||
@@ -6,7 +6,7 @@ This script is a simple wrapper for SQLite3, MySQL and PgSQL, for make possible
|
||||
|
||||
In composer:
|
||||
```bash
|
||||
composer require jkanetwork/dbwrapper "~1.4.2"
|
||||
composer require jkanetwork/dbwrapper "~1.5.0"
|
||||
```
|
||||
|
||||
By hand: Download the php file inside src folder
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/* DBWrapper.php - Version 1.4.2
|
||||
/* DBWrapper.php - Version 1.5
|
||||
This script is a simple wrapper for SQLite3, MySQL and PgSQL,
|
||||
for make possible to use different BD systems without changing the functions.
|
||||
For use, in dbw_connect you have to specify type of database (see below)
|
||||
@@ -12,19 +12,19 @@ function dbw_connect($tdb,$server,$database=NULL,$user = NULL,$password=NULL){
|
||||
switch ($tdb){
|
||||
case "mysql":
|
||||
case "mysqli":
|
||||
$return[0] = mysqli_connect($server,$user,$password,$database) or die("Error de conexion");
|
||||
$return[0] = mysqli_connect($server,$user,$password,$database) or throwExceptionDBConn();
|
||||
$return[1] = "mysqli"; //Return standard mysqli for other funcs.
|
||||
break;
|
||||
case "sqlite":
|
||||
case "sqlite3":
|
||||
$return[0] = new SQLite3($server);
|
||||
if (!$return[0]) die ("Error de conexion");
|
||||
if (!$return[0]) throwExceptionDBConn();
|
||||
$return[1] = "sqlite"; //Return standard SQLite3 for other funcs.
|
||||
break;
|
||||
case "PostgreSQL":
|
||||
case "pg":
|
||||
case "PgSQL":
|
||||
$return[0] = pg_connect("host=$server dbname=$database user=$user password=$password") or die ('Error de conexion: ' . 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.
|
||||
break;
|
||||
default:
|
||||
@@ -34,6 +34,10 @@ function dbw_connect($tdb,$server,$database=NULL,$user = NULL,$password=NULL){
|
||||
return $return;
|
||||
}
|
||||
|
||||
function throwExceptionDBConn() {
|
||||
throw new Exception('Database connection error');
|
||||
}
|
||||
|
||||
/** Escapes conflictive chars for inserting into database */
|
||||
function dbw_escape_string($conn,$string){
|
||||
switch ($conn[1]){
|
||||
@@ -105,7 +109,7 @@ function dbw_query_fetch_array($conn,$query){
|
||||
case "PgSQL":
|
||||
$result = pg_query($query);
|
||||
if (!$result){return false;}
|
||||
$ret = pg_fetch_array($result); //Last error (pg_last_error()) not implemented
|
||||
$ret = pg_fetch_array($result);
|
||||
break;
|
||||
}
|
||||
//echo "<p>".$query."->".(microtime(true)-$time)." milisegundos</p>";
|
||||
@@ -131,11 +135,16 @@ function dbw_query_goto($conn,$result,$row = 0){
|
||||
}
|
||||
}
|
||||
|
||||
/** Does multiple querys in one command */
|
||||
function dbw_multi_query($conn,$query){
|
||||
/** Does multiple querys in one command
|
||||
* The erasebuffer command, in mysqli is neccesary if its only a insert for avoid problems in next querys
|
||||
*/
|
||||
function dbw_multi_query($conn,$query,$erasebuffer = 0){
|
||||
switch ($conn[1]){
|
||||
case "mysqli":
|
||||
mysqli_multi_query($conn[0],$query);
|
||||
if ($erasebuffer){
|
||||
while(mysqli_next_result($conn[0])){;} //Erase multiquery output for avoid error in next query
|
||||
}
|
||||
break;
|
||||
case "sqlite":
|
||||
$conn[0]->exec($query);
|
||||
@@ -178,6 +187,18 @@ function dbw_num_rows($conn,$result){
|
||||
}
|
||||
}
|
||||
|
||||
/** Escapes conflictive chars for inserting into database */
|
||||
function dbw_free_result($conn,$result){
|
||||
switch ($conn[1]){
|
||||
case "mysqli":
|
||||
return mysqli_free_result($string);
|
||||
case "sqlite":
|
||||
return NULL; //Not neccesary I think
|
||||
case "PgSQL":
|
||||
return NULL; //¿?
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Close connection */
|
||||
function dbw_close($conn){
|
||||
|
||||
Reference in New Issue
Block a user