PHP operation MySQL

Source: Internet
Author: User

Due to the previous database field design problems, not too much attention, field content, background python data directly inserted, did not do processing, the data do not want to lose, only the Site database field content
Processing, 1 million data, debugging a half-day, a lot of ideas have tried, all kinds of pits, get a night, almost spit blood, finally got
<?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 '];
$sql 2= "INSERT into share_file values (' $res _id ', ' $real _url ', ' $uk ', ' $res _title ', ' $res _cate ', ' $res _size ', ' $res _times ' ‘)";



Var_dump ($sql 2);
$res _bool=mysql_query ($sql 2, $conn);
if (! $res _bool) {
echo 0;
}else{

if (Mysql_affected_rows ($conn) >0) {
Echo 1;//indicates successful execution
}else{
Echo 2;
}
}
}


Mysql_close ($conn);

PHP operation MySQL

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.