<? PHP
/* This is basically the Database Class I use */
// Block undefined errors
Error_reporting (7 );
Class db_mysql {
VaR $ servername = "localhost ";
VaR $ dbname = "DBASE ";
VaR $ dbusername = "root ";
VaR $ dbpassword = "";
VaR $ conn = 0;
VaR $ technicalemail = 'java @ cu165.com ';
Function geterrdesc (){
$ This-> error = @ mysql_error ($ this-> conn );
Return $ this-> error;
}
Function geterrno (){
$ This-> errno = @ mysql_errno ($ this-> conn );
Return $ 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 ("invalid SQL:". $ QUERY_STRING );
}
Return $ this-> result;
}
Function num_rows ($ queryid ){
$ This-> rows = mysql_num_rows ($ queryid );
If (empty ($ queryid )){
$ This-> halt ("invalid query ID:". $ queryid );
}
Return $ this-> rows;
}
Function fetch_array ($ queryid ){
$ This-> record = mysql_fetch_array ($ queryid );
If (empty ($ queryid )){
$ This-> halt ("invalid query ID:". $ queryid );
}
Return $ this-> record;
}
Function conn (){
$ This-> conn = mysql_connect ($ this-> servername, $ this-> dbusername, $ this-> dbpassword) or die (mysql_error ("database link failed "));
Return $ this-> conn;
}
Function selectdb (){
If (! Mysql_select_db ($ this-> dbname )){
$ This-> halt ("database link failed ");
}
}
Function my_close (){
// Mysql_close ($ this-> conn );
Mysql_close ();
}
Function fetch_row ($ queryid ){
$ This-> record = mysql_fetch_row ($ queryid );
If (empty ($ queryid )){
$ This-> halt ("invalid queryid:". $ 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 ("invalid query ID:". $ query );
}
Return $ this-> record;
}
Function fetch_one_array ($ query ){
$ This-> result = $ this-> query ($ query );
$ This-> record = $ this-> fetch_array ($ this-> result );
If (empty ($ query )){
$ This-> halt ("invalid query ID:". $ 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-> insertid;
}
/* ===================================================== ========================================= */
// Create an array from a multidimensponarray returning formatted
// Strings ready to use in an insert query, saves having to manually format
// The (insert into Table) ('field', '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,
);
}
/* ===================================================== ========================================= */
// Create an array from a multidimensponarray returning a formatted
// String ready to use in an update query, saves having to manually format
// The 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 = "<HTML>/n $ Message. = "<meta content =/" text/html; charset = gb2312/"http-equiv =/" Content-Type/">/N ";
$ Message. = "<style type =/" text/CSS/">/N ";
$ Message. = "<! --/N ";
$ Message. = "body, TD, P, pre {/N ";
$ Message. = "font-family: verdana, Arial, Helvetica, sans-serif; font-size: 12px;/N ";
$ Message. = "}/N ";
$ Message. = "</style>/N ";
$ Message. = "$ Message. = "<body bgcolor =/" # eeeeee/"text =/" #000000/"link =/" #006699/"vlink =/" #5493b4/">/N";
$ Message. = "<font size = 10> <B> system debugging </B> </font> <font size = 6> <B> (by cabbage core) </B> </font>/n <HR noshade size = 1>/N ";
$ Content = "<p> database error: </P> <PRE> <B> ". htmlspecialchars ($ MSG ). "</B> </PRE>/N ";
$ Content. = "<B> MySQL error description </B>:". $ this-> geterrdesc (). "/n <br> ";
$ Content. = "<B> MySQL error number </B>:". $ this-> geterrno (). "/n <br> ";
$ Content. = "<B> date </B>:". date ("Y-m-d @ H: I"). "/n <br> ";
$ Content. = "<B> script </B>: http ://". $ _ server [http_host]. getenv ("request_uri "). "/n <br> ";
$ Content. = "<B> Referer </B>:". getenv ("http_referer"). "/n <br> ";
$ Message. = $ content;
$ Message. = "<p> Please refresh your browser. If it still cannot be displayed normally, contact <a href =/" technicalemail. "/'> mailto :". $ this-> technicalemail. "/"> administrator </a>. </P> ";
$ Message. = "</body>/n Echo $ message;
$ Headers = "from: nt.cn <$ this-> technicalemail>/R/N ";
$ Content = strip_tags ($ content );
@ Mail ($ technicalemail, "database error", $ content, $ headers );
Exit;
}
}
?>