<? 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 = * @ *. 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 ("/'/", "http://www.cnblogs.com/viso#se/admin/file://'/", $ 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 ("/'/", "http://www.cnblogs.com/viso#se/admin/file://'/", $ v );
$ Return_string. = $ k. "= '". $ v ."',";
}
$ Return_string = preg_replace ("/, $/", "", $ return_string );
Return $ return_string;
}
Function halt ($ msg ){
Global $ technicalemail, $ debug;
$ Message = "$ 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
$ 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://www.cnblogs.com/viso#se/admin/'http://> ";
$ 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;
}
}
?>