diff --git a/src/dbwrapper.php b/src/dbwrapper.php index 78c6b06..1cd97fe 100644 --- a/src/dbwrapper.php +++ b/src/dbwrapper.php @@ -1,5 +1,5 @@ fetchArray()) { //There is not fetchAll in sqlite3, implement it + $ret[] = ($row); + } + break; + case "PgSQL": + $ret = pg_fetch_all($result,PGSQL_ASSOC); + break; + } + //echo "
".$query."->".(microtime(true)-$time)." milisegundos
"; + return $ret; +} + +/** Make query and fetch array (For one result) */ +function dbw_query_fetch_array($conn,$query,$typearray = NULL){ $time = microtime(true); $ret=null; switch ($conn[1]){ case "mysqli": $result = mysqli_query($conn[0],$query); if (!$result){return false;} - $ret = mysqli_fetch_array($result); + if ($typearray == NULL || $typearray == "BOTH"){$ret = mysqli_fetch_array($result,MYSQLI_BOTH);} + if ($typearray == "ASSOC"){$ret = mysqli_fetch_array($result,MYSQLI_ASSOC);} + if ($typearray == "NUM"){$ret = mysqli_fetch_array($result,MYSQLI_NUM);} break; case "sqlite": $result = $conn[0]->query($query); @@ -111,13 +137,44 @@ function dbw_query_fetch_array($conn,$query){ case "PgSQL": $result = pg_query($query); if (!$result){return false;} - $ret = pg_fetch_array($result); + $ret = pg_fetch_array($result,PGSQL_ASSOC); break; } //echo "".$query."->".(microtime(true)-$time)." milisegundos
"; return $ret; } +/** Make query and fetch all in a array */ +function dbw_query_fetch_all($conn,$query,$typearray = NULL){ + $time = microtime(true); + $ret=null; + switch ($conn[1]){ + case "mysqli": + $result = mysqli_query($conn[0],$query); + if (!$result){return false;} + if ($typearray == NULL || $typearray == "BOTH"){$ret = mysqli_fetch_all($result,MYSQLI_BOTH);} + if ($typearray == "ASSOC"){$ret = mysqli_fetch_all($result,MYSQLI_ASSOC);} + if ($typearray == "NUM"){$ret = mysqli_fetch_all($result,MYSQLI_NUM);} + break; + case "sqlite": + $result = $conn[0]->query($query); + if (!$result){return false;} + $ret = array(); + while ($row = $result->fetchArray()) { //There is not fetchAll in sqlite3, implement it + $ret[] = ($row); + } + break; + case "PgSQL": + $result = pg_query($query); + if (!$result){return false;} + $ret = pg_fetch_all($result,PGSQL_ASSOC); + break; + } + //echo "".$query."->".(microtime(true)-$time)." milisegundos
"; + return $ret; +} + + /** Goes a query to $row. $row starts in 0 as first row as if not specified */ function dbw_query_goto($conn,$result,$row = 0){ switch ($conn[1]){ @@ -227,4 +284,4 @@ function dbw_result_seek($conn,$result){return dbw_query_goto($conn,$result,$row function dbw_insert_id($conn){return dbw_last_id($conn);} -?> \ No newline at end of file +?>