Convert OICQ data to MYSQL data

Source: Internet
Author: User
Convert OICQ data to MYSQL data. This file is/tmp/phpBeoJQ5.
################ You can copy this code to test ################ #

Include ("include/dbclass. inc"); // replace the test with MYSQL. INC.
$ Q = new DB_ SQL;

$ Db = $ q-> Database; // define the database
Mysql_connect ('localhost: 100', $ q-> User, $ q-> Password );
?>




Function show_field ($ db, $ table, $ num, $ selected_field ){
$ Result = mysql_db_query ($ db, "show keys from $ table") or mysql_die ();
$ Primary = "";
While ($ row = mysql_fetch_array ($ result ))
If ($ row ["Key_name"] = "PRIMARY ")
$ Primary. = "$ row [Column_name],";
$ Result = mysql_db_query ($ db, "show fields from $ table ");
If (! $ Result ){
Mysql_die ();
}
Else {
Echo" N ";While ($ row = mysql_fetch_array ($ result )){$ Selected = ($ selected_field = $ row ["Field"])? "Selected ":"";Echo"".$ Row ["Field"]."N ";}Echo"Nn ";
}
}

Function show_table ($ db, $ selected_table ){
$ Tables = mysql_list_tables ($ db );
$ Num_tables = @ mysql_numrows ($ tables );
If ($ num_tables = 0 ){
Echo "no table yet ";
}
Else {
$ I = 0;
Echo" N ";While ($ I <$ num_tables ){$ Table = mysql_tablename ($ tables, $ I );$ Selected = ($ selected_table = $ table )? "Selected ":"";Echo"$ TableN ";$ I ++;}Echo"Nn ";
}
}

If ($ submit ){
If (! Empty ($ csv_file) & $ csv_file! = "None "){
// $ Csv_file = stripslashes ($ csv_file );
$ Fp = fopen ($ csv_file, "r ");

// Show first line of the csv file to select dababase table and its fields
Echo"

N ";

// When click 'OK' button, start insert data
If ($ submit = "OK "){
$ NO = 1;
While ($ csv_data = fgetcsv ($ fp, 2000, "$ terminated ")){
// $ Num = count ($ csv_data );
For ($ c = 0; $ c <$ num; $ c ++ ){

$ Table_field_name = "field $ c ";
$ First_3 = substr ($ table_field_name, 0, 3 );
$ First_2 = substr ($ table_field_name, 0, 2 );
$ Val_tmp = ($ first_3 = "fid" | $ first_3 = "int"
| $ First_2 = "id ")?
$ Csv_data [$ c]: "'". $ csv_data [$ c]. "'";
$ Val. = $ val_tmp .",";
$ Var. = $ table_field_name .",";
}
$ Val = substr ($ val, 0,-1 );
$ Var = substr ($ var, 0,-1 );
$ Query = "insert into $ table ($ var) VALUES ($ val )";
$ Val = "";
$ Var = "";
$ Q-> query ($ query );
Echo "NO. $ NO $ query

";
$ NO ++;
}
Fclose ($ fp );
}

}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.