6 Commits
1.4.1 ... 1.4.2

Author SHA1 Message Date
45cb93991c Update README.md for 1.4.2 2018-03-31 12:21:47 +00:00
69a9f230da Emulating num_rows for sqlite3 when is needed (Sqlite3 doesn't have that natively) 2018-03-31 12:21:13 +00:00
b738eda270 License like https://spdx.org/licenses/ 2018-01-30 22:52:45 +00:00
926a16ef65 Update README.md 2017-10-22 17:04:37 +00:00
Jose Luis “JoseluCross” Garrido Labrador
4a4b641dc6 Update README.md 2017-09-21 23:31:24 +00:00
joselucross
8098979bdf Update README.md 2017-09-22 01:27:32 +02:00
3 changed files with 43 additions and 17 deletions

View File

@@ -1,7 +1,16 @@
# DBWrapper - Version 1.4.1
# DBWrapper - Version 1.4.2
This script is a simple wrapper for SQLite3, MySQL and PgSQL, for make possible to use different BD systems without changing the functions.
## Installation
In composer:
```bash
composer require jkanetwork/dbwrapper "~1.4.2"
```
By hand: Download the php file inside src folder
## Avalible functions:
* To connect

View File

@@ -3,7 +3,7 @@
"type": "library",
"description": "MySQL, PgSQL and SQLite wrapper",
"keywords": ["mysql", "PgSQL", "sqlite", "wrapper"],
"license": "APACHE",
"license": "Apache-2.0",
"authors": [
{"name": "Kevin Puertas Ruiz", "email": "kevin01010@gmail.com"}
],

View File

@@ -1,5 +1,5 @@
<?php
/* DBWrapper.php - Version 1.4.1
/* DBWrapper.php - Version 1.4.2
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)
@@ -49,14 +49,20 @@ function dbw_escape_string($conn,$string){
/** Make query */
function dbw_query($conn,$query){
$time = microtime(true);
switch ($conn[1]){
case "mysqli":
return mysqli_query($conn[0],$query);
$ret = mysqli_query($conn[0],$query);
break;
case "sqlite":
return $conn[0]->query($query);
$ret = $conn[0]->query($query);
break;
case "PgSQL":
return pg_query($query); //Last error (pg_last_error()) not implemented
$ret = pg_query($query);
break;
}
//echo "<p>".$query."->".(microtime(true)-$time)." milisegundos</p>";
return $ret;
}
/** Fetch array from query */
@@ -83,23 +89,27 @@ function dbw_fetch_array($conn,$result,$typearray = NULL){
/** Make query and fetch array */
function dbw_query_fetch_array($conn,$query){
$time = microtime(true);
switch ($conn[1]){
case "mysqli":
$query = mysqli_query($conn[0],$query);
if ($query == false || $query == NULL){return false;}
return mysqli_fetch_array($query);
$result = mysqli_query($conn[0],$query);
if (!$result){return false;}
$ret = mysqli_fetch_array($result);
break;
case "sqlite":
$query = $conn[0]->query($query);
if ($query == false || $query == NULL){return false;}
return $query->fetchArray();
$result = $conn[0]->query($query);
if (!$result){return false;}
$ret = $result->fetchArray();
break;
case "PgSQL":
$query = pg_query($query);
if ($query == false || $query == NULL){return false;}
return pg_fetch_array($query); //Last error (pg_last_error()) not implemented
$result = pg_query($query);
if (!$result){return false;}
$ret = pg_fetch_array($result); //Last error (pg_last_error()) not implemented
break;
}
//echo "<p>".$query."->".(microtime(true)-$time)." milisegundos</p>";
return $ret;
}
/** Goes a query to $row. $row starts in 0 as first row as if not specified */
@@ -155,7 +165,14 @@ function dbw_num_rows($conn,$result){
case "mysqli":
return mysqli_num_rows($result);
case "sqlite":
return $result->numRows();
//Emulating num_rows. Is faster to use a COUNT(*), but for make it work...
$count=0;
$result->reset(); //Reset pointer
while($row = $result->fetchArray(SQLITE3_ASSOC)){
$count++;
}
$result->reset(); //Reset pointer
return $count;
case "PgSQL":
return pg_num_rows ($result);
}