php 操作mysql

來源:互聯網
上載者:User

標籤:insert   row   mit   baidu   roo   share   value   title   else   

//由於前期資料庫欄位設計問題,沒太注意,欄位內容,後台python採集資料直接插入,沒做處理,資料又不想丟掉,只能對網站資料庫欄位內容
進行處理,100萬條資料,調試了半天,很多思路都試過,各種坑,弄了一個晚上,差點吐血,終於弄好了
<?php
$conn=mysql_connect("localhost","root","123qwe");


mysql_select_db("baidu",$conn);


mysql_query("set names utf8");
//???????
$sql="select * from bdres limit 0,100000";


$res=mysql_query($sql,$conn) ;

   $arr=array();

while ($row=mysql_fetch_assoc($res)){
$arr[]=$row;
}
mysql_free_result($res);



for($i=0;$i<count($arr);$i++){
    $row=$arr[$i];
if(!$row[‘res_times‘]){
$row[‘res_times‘]=0;
}



$str=$row[‘res_times‘];
//var_dump($str);

$row[‘res_times‘]=preg_replace("/[^A-Za-z0-9\.\-]/","",$str);

$res_id=$row[‘res_id‘];
$real_url=$row[‘real_url‘];
$uk=$row[‘uk‘];
$res_title=$row[‘res_title‘];
$res_cate=$row[‘res_cate‘];
$res_size=$row[‘res_size‘];
$res_times=$row[‘res_times‘];
$sql2="insert into share_file values(‘$res_id‘,‘$real_url‘,‘$uk‘,‘$res_title‘,‘$res_cate‘,‘$res_size‘,‘$res_times‘)";



//var_dump($sql2);
$res_bool=mysql_query($sql2,$conn);
if(!$res_bool){
echo 0;  
}else{

if(mysql_affected_rows($conn)>0){
echo 1;//表示執行成功
}else{
echo 2;
}
}



mysql_close($conn);

php 操作mysql

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.