Need opinion of Database function helper script

I put this together to make my life easier when working with databases, I figer why not clean it up and see if it might be useful for others, though I don’t know how others would see it or if it would even work right for others, mind digging into this bad boy and telling me what you think?

[php]<?php

//mysql settings leave blank if not using

$server = ‘’
$database = ‘’
$user = ‘’
$password = ‘’

//name of the sqlite file, please make it like ‘Data.db’ or something simaular, leave blank if not using
$sqlite_db_file = ‘’

/*

#if you want to use mysql use

db_query(‘QUERY STRING HERE’, 1);


#or if you want to use sqlite use

db_query(‘QUERY STRING HERE’, 2);


#if you want to excute a large batch of sqlite querys with no result given back (like setting up tables and watnot),
#then use

db_query(‘blabla; bla bla blabla; bla bla’, 2.1);


#if you wish to use both (be careful as some things are not supported in sqlite syntax,
#also magic qoutes are stripped before the query is sent to the sqlite engine) then use this

db_query(‘QUERY STRING HERE’, 3);

#this one returns an array with the querys result like this

$result = db_query(‘bla bla’, 3);

$result[0] . $result[1]

where as
$result[0] = mysql result
$result[1] = sqlite result

#if you wish to get errors printed from mysql put a 1 after the db like so

db_query(‘query’, 1, 1);

or print errors for sqlite like so

db_query(‘query’, 2, 2);

#or print errors for both use

db_query(‘query’, 3, 3);

*/

/************************************




*************************************/

//now for the funtion DO NOT EDIT

if($server != ‘’ && $user != ‘’ && $database != ‘’){
mysqlconnect($server, $user, $password);
mysql_select_db($database);
}

if($sqlite_db_file != ‘’){
$sqlite_db_rl = sqlite_open(’./’ . $sqlite_db_file);

function db_query($query, $db, $error = 0){
global $sqlite_db_rl;
if($db == 1){
$result = mysql_query($query);
}
if($db == 2){
$result = sqlite_query($sqlite_db_rl, $query);
}
if($db == 2.1){
sqlite_exec($sqlite_db_rl, $query);
}
if($db == 3){
$result[] = mysql_query($query);
$query = str_replace(’`’, ‘’, $query);
$result[] = sqlite_query($sqlite_db_rl, $query);
}
return $result;
if($error == 1){
echo mysql_error();
}
if($error == 2){
echo sqlite_error_string(sqlite_last_error());
}
if($error == 3){
echo mysql_error() . ‘

’ . sqlite_error_string(sqlite_last_error());
}
}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service