Hey,
i use a file with all my queries but i want to make it even better by making a file called mysql.php which will consist of all the DB select/update/delete/insert function so instead of using in every qurey:
$result = mysql_query("SELECT * FROM person");while($row = mysql_fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />"
}
I will put in the mysql.php file a function that called 'select' then i will use the function in everyfile i want as this:
include("mysql.php");
$result = $DB->select("SELECT * FROM person");
while($row = $DB->fetch_array($result))
{
echo $row['FirstName'] . " " . $row['LastName'];
echo "<br />"
}
this is an example of just the select function but i want to do it to select/update/delete/insert so there is no complications.
Im sure im making myself clear but does anyone have something like that already coded i would like taking alook at it.
here is an example of IPS mysql DB abstraction:
* Update:
* $db->do_update( 'table', array( 'field' => 'value', 'field2' => 'value2' ), 'id=1' );
* Insert
* $db->do_insert( 'table', array( 'field' => 'value', 'field2' => 'value2' ) );
/*-------------------------------------------------------------------------*/
// Quick function: DO UPDATE
/*-------------------------------------------------------------------------*/
function do_update( $tbl, $arr, $where="", $shutdown=FALSE )
{
//-----------------------------------------
// Form query
//-----------------------------------------
$dba = $this->compile_db_update_string( $arr );
$query = "UPDATE ".$this->obj['sql_tbl_prefix']."$tbl SET $dba";
if ( $where )
{
$query .= " WHERE ".$where;
}
//-----------------------------------------
// Shut down query?
//-----------------------------------------
$this->no_prefix_convert = 1;
if ( $shutdown )
{
if ( ! $this->obj['use_shutdown'] )
{
$this->is_shutdown = 1;
$return = $this->query( $query );
$this->no_prefix_convert = 0;
$this->is_shutdown = 0;
return $return;
}
else
{
$this->obj['shutdown_queries'][] = $query;
$this->no_prefix_convert = 0;
$this->cur_query = "";
}
}
else
{
$return = $this->query( $query );
$this->no_prefix_convert = 0;
return $return;
}
}
/*-------------------------------------------------------------------------*/
// Quick function: DO INSERT
/*-------------------------------------------------------------------------*/
function do_insert( $tbl, $arr, $shutdown=FALSE )
{
//-----------------------------------------
// Form query
//-----------------------------------------
$dba = $this->compile_db_insert_string( $arr );
$query = "INSERT INTO ".$this->obj['sql_tbl_prefix']."$tbl ({$dba['FIELD_NAMES']}) VALUES({$dba['FIELD_VALUES']})";
//-----------------------------------------
// Shut down query?
//-----------------------------------------
$this->no_prefix_convert = 1;
if ( $shutdown )
{
if ( ! $this->obj['use_shutdown'] )
{
$this->is_shutdown = 1;
$return = $this->query( $query );
$this->no_prefix_convert = 0;
$this->is_shutdown = 0;
return $return;
}
else
{
$this->obj['shutdown_queries'][] = $query;
$this->no_prefix_convert = 0;
$this->cur_query = "";
}
}
else
{
$return = $this->query( $query );
$this->no_prefix_convert = 0;
return $return;
}
}
something like that, of course no need for all that something simple that will make the job.
would appreciate any help, thanks vadim.