vadim88 Posted February 4, 2008 Share Posted February 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/ Share on other sites More sharing options...
trq Posted February 4, 2008 Share Posted February 4, 2008 Whats your problem exactly? Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-457714 Share on other sites More sharing options...
vadim88 Posted February 4, 2008 Author Share Posted February 4, 2008 i want a code that will i would use this: $db->do_insert( 'table', array( 'field' => 'value', 'field2' => 'value2' ) ); instead of the whole insert function in order to insert something to the database, i think its called DB abstraction, i posted an example in the last code box . Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-457781 Share on other sites More sharing options...
trq Posted February 4, 2008 Share Posted February 4, 2008 And what do you want from us? Where are you stuck? You want us to write it? Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-457814 Share on other sites More sharing options...
vadim88 Posted February 4, 2008 Author Share Posted February 4, 2008 help with it, i dont really know how to do that, i dont ask u to write the whole thing just if it's possible to write at least the select function thing so i could see how it works and try to write down the others by myself, there is no tutorial nor and kind of article that explains how this can be done. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-457819 Share on other sites More sharing options...
vadim88 Posted February 4, 2008 Author Share Posted February 4, 2008 bump... Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-457931 Share on other sites More sharing options...
trq Posted February 5, 2008 Share Posted February 5, 2008 You just posted an example, whats wrong with that? Quote Link to comment https://forums.phpfreaks.com/topic/89383-db-abstraction/#findComment-458784 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.