PHP
/ * This basically is the database class I use * /// shield undefined error error_reporting (7);
Class DB_MYSQL {
Var $ servername = "localhost"; var $ dbname = "dbase"; var $ dbusername = "root"; var $ dbpassword = "; var $ conn = 0; var $tenicalemail='java@cu165.com ';
Function geterrdesc () {$ this-> Error = @Mysql_ERROR ($ this-> conn); return $ this-> error;}
Function geterrno () {$ this-> errno = @mysql_errno ($ this-> conn); returnid $ this-> errno;}
Function Query ($ query_string) {
// $ this-> Result = mysql_db_query ($ this-> dbname, $ query_string); $ this-> result = mysql_query ($ query_string); if (! $ this-> result) {$ this-> Halt ("SQL Invalid: "$ query_string;}
Return $ this-> Result;
Function Num_Rows ($ queryid) {
$ this-> rows = mysql_num_rows ($ queryid);
IF (Empty ($ this-> Halt ("Query ID is invalid:". $ queryid);} Return $ this-> rows;}
Function Fetch_Array ($ queryid) {
$ this-> record = mysql_fetch_array ($ queryid); if ($ this-> Halt) {$ this-> Halt ("Query ID is invalid:". $ queryid);} Return $ this-> Record;}
Function conn ($ this-> conn = mysql_connect ($ this-> Servername, $ this-> dbusername, $ this-> dbpassword) or Die (MySQL_ERROR ("Database Link Fail"); Return $ this-> conn }
Function selectdb () {if (! mysql_select_db ($ this-> dbname)) {$ this-> Halt ("Database Link Fail");}}
Function my_close () {// mysql_close ($ this-> conn); mysql_close ();}
Function Fetch_Row ($ queryid) {
$ this-> record = mysql_fetch_row ($ queryid); if ($ this-> halt) {$ this-> Halt ("QueryID invalid:". $ queryid);} Return $ this-> record;}
Function fetch_one_num ($ query) {
$ this-> result = $ this-> query ($ query); $ this-> record = $ this-> num_rows ($ this-> result); if (Empty ($ query)) {$ this-> Halt "Query ID is invalid:" $ query);} Return $ this-> record;} function fetch_one_Array ($ query) {
$ this-> Result = $ this-> query ($ qery); $ this-> record = $ this-> fetch_array ($ this-> result); if ($ this-> halt) {$ this-> halt "Query ID is invalid:" $ query);} Return $ this-> record;
}
Function Free_Result ($ query) {if (! MySQL_FREE_RESULT ($ query)) {$ this-> halt ("fail to mysql_free_result);}}
Function INSERT_ID () {$ this-> INSERTID = mysql_insert_id (); if (! $ this-> insertid) {$ this-> Halt ("fail to get mysql_insert_id");} Return $ this-> insert;
/ * ================================================================================================================================================================ ==============================================11, SAVING, SAVES HAVING To Manually Format // The (Insert Into Table) ('Field', 'Field') Values ('Val', 'Val') / * ============== ============================================================================================================================================================================================================= ========= * /
Function compile_db_insert_string ($ data) {$ Field_Names = ""; $ field_values = "
Foreach ($ DATA AS $ K => $ V) {$ V = preg_replace ("/ '/", "//'", $ V); // $ v = preg_replace ("/ # /", "// # ", $ V); $ field_names. =" $ k, "; $ field_values. =" '$ V', ";
$ field_names = preg_replace ("/, $ /", ", $ field_names); $ field_values = preg_replace (" /, $ / ",", ", $ field_values);
Return Array ('Field_Names' => $ FIELD_NAMES, 'Field_Values' => $ FIELD_VALUES,);
/ * ================================================================================================================================================================ ===============================================, SAVES Having to manually format /// Field = 'Val', Field = 'val', Field = 'val' / * ========================= ======================================================== * /
Function compile_db_update_string ($ data) {
$ RETURN_STRING = ""
Foreach ($ DATA AS $ K => $ V) {$ V = preg_replace ("/ '/", "//'", $ V); $ RETURN_STRING. = $ K. "= '". $ V. " ', ";} $ RETURN_STRING = preg_replace (" /, $ / "," ", $ return_string);
Return $ RETURN_STRING;
Function Halt ($ msg) {
Global $ TECHNICALEMAIL, $ DEBUG
$ Message = " / n
/ n"; $ message. = " / n $ Message. = "