################# You can copy this code to test #################

<?
include("include/dbclass.inc"); //可以用 MYSQL.INC 類代替測試
$q = new DB_Sql;

$db = $q- " /> 国产偷久久,天天色天天射综合网,欧美成人二区

一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù)

This file is /tmp/phpBeoJQ5 .  
################# You can copy this code to test #################  

<?  
include("include/dbclass.inc"); //可以用 MYSQL.INC 類代替測試  
$q = new DB_Sql;  

$db = $q->Database; //define the database  
mysql_connect('localhost:3306',$q->User,$q->Password);  
?>  

<form method="post" action="<?php echo $php_SELF;?>"  
enctype="multipart/form-data">  
<input type="file" name="csv_file"  
value="<?php echo $csv_file;?>">    
terminated by <input type="text" name="terminated"  
value="," size=2><p>  
Which table you want to insert ?  
<?php show_table($db,$table); ?><p>  
<input type="submit" name="submit" value="go">  
</form>  

<?php  

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 "<select name=field$num>n";  
while ($row= mysql_fetch_array($result)) {  
$selected = ($selected_field == $row["Field"]) ? "selected" : "";  
echo "<option value=" . $row["Field"] . " $selected>" .  
$row["Field"] . "</option>n";  
}  
echo "</select>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 "<select name=table>n";  
while ($i < $num_tables) {  
$table = mysql_tablename($tables, $i);  
$selected = ($selected_table == $table) ? "selected" : "";  
echo "<option value=$table $selected>$table</option>n";  
$i++;  
}  
echo "</select>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 "<form method=post action=$php_SELF>";  

$csv_data = fgetcsv($fp, 2000, "$terminated");  
$num = count($csv_data);  
for ( $c=0; $c<$num; $c++ ) {  

$field_name[$c] = $csv_data[$c];  
echo $field_name[$c] . "  n";  

$table_field_name = "field$c";  
show_field($db,$table,$c,$$table_field_name);  
echo "<br>";  
}  

// copy the tmp file for next use  
$dest = "/tmp/csv_file.csv";  
copy($csv_file,$dest);  

echo "<input type=hidden name=csv_file value=$dest>n" .  
"<input type=hidden name=table value=$table>n" .  
"<input type=hidden name=terminated value=$terminated>n" .  
"<input type=submit name=submit value=ok></form><p>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<p>";  
$NO++;  
}  
fclose($fp);  
}  

}  
}  
?>  

php技術(shù)將OICQ數(shù)據(jù)轉(zhuǎn)成MYSQL數(shù)據(jù),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 91国语精品自产拍在线观看性色 | 亚洲精品成人在线 | 久久九九亚洲精品 | 激情五月宗合网 | 激情文学亚洲 | 高清国产美女一级毛片 | 2021最新在线精品国产 | 色黄啪啪网18勿进 | 大香网伊人久久综合网2020 | 精品久久久久久久免费加勒比 | 色视频网 | 色月| 国产美女无遮挡免费视频 | 黄色大片免费看 | 综合久久久久 | 亚洲欧美国产18 | 精品久久久久久久久久中文字幕 | 午夜小视频网站 | 成人在线第一页 | 亚洲国产99 | 色多多免费视频观看区一区 | 久久免费福利视频 | 亚洲国产精品成人午夜在线观看 | 91精品91 | 精品成人一区二区 | 美女扒开下面无遮挡免费视频 | 成人97在线观看免费高清 | 二区三区| 婷婷网五月天天综合天天爱 | 91视频18| 奇米第四狠狠777高清秒播 | 色毛片| 国产精品极品美女自在线 | 成年美女黄网站色视频大全免费 | 91原创视频在线观看 | 国产这里有精品 | 在线观看视频网站www色 | 2022免费国产精品福利在线 | 日韩精品亚洲专区在线影视 | 国产91视频观看 | 精品91一区二区三区 |