<? Php Header ('HTTP-equiv = "Content-Type" content = "text/html; charset = UTF-8 "'); $ DB_host = "localhost"; // Database Host $ DB_user = "root"; // Database User $ DB_psw = "root3306"; // Database Password $ DB_datebase = "gk_yue39_com"; // Database Name $ DB_charset = "utf8"; // database Character Set $ Dbprefix = "yue392_com _"; $ New_dbprefix = "yue39_com _"; $ Db = new mysqli ($ DB_host, $ DB_user, $ DB_psw); // instantiate an object
// Check the connection If (mysqli_connect_errno ()){ Printf ("Connect failed: % sn", mysqli_connect_error ()); Exit (); } $ Db-> select_db ($ DB_datebase); // Select Operation Database $ Db-> set_charset ($ DB_charset); // sets the database character set. // Execute a query $ SQL = 'show tables '; $ Result = $ db-> query ($ SQL ); Echo $ result-> num_rows. 'row result'. $ result-> field_count. 'column content <br/> '; // $ Result-> data_seek ('5'); // obtain the result starting from 5th entries in the result set Echo '<table border = "1" cellspacing = "0" cellpadding = "0" align = "center" width = "90%"> '; // Cyclic output field name // $ Result-> field_seek (2); // obtain the result from 2nd entries in the field set While (true = ($ field = $ result-> fetch_field ())){ Echo '<th> '. $ result-> current_field. '_'. $ field-> name. '('. $ field-> length. ') </th> '; } // Output query results cyclically While (true = ($ row = $ result-> fetch_assoc ())){ Echo '<tr> '; Foreach ($ row as $ col ){ $ SQL = "rename table". $ col. "'to'". str_replace ($ dbprefix, $ new_dbprefix, $ col )."'"; If ($ db-> query ($ SQL )){ Echo '<td align = "center"> '. $ SQL. '</td> <font color = "blue"> success </font> </td> '; } Else { Echo '<td align = "center"> '. $ SQL. '</td> <font color = "red"> failed </font> </td> '; } } Echo '</tr> '; } Echo '</table> '; $ Result-> free (); // release the result set $ Db-> close (); // close the connection ?> |