php 骚操作把文本写到数据中

版权声明:独学而无友,则孤陋寡闻。q群582951247 https://blog.csdn.net/mp624183768/article/details/88216352

需求 一个数据库记录了一个url地址 这个地址是我们的txt文件 要把这个内容写到新的字段中来

添加字段

    $tabName = 'la_goods';
//
    $sql = "alter table `{$tabName}` add `bdy_content` LONGTEXT NOT NULL COMMENT '百度云地址内容'";
    if (!$obj = mysqli_query($con, $sql)) {
//        die(mysqli_error($con) . $sql);
        //字段已经存在 会报错加不上去但是不用管
    }

骚操作 

$tabName = 'la_goods';
$con = mysqlinit();
//获取文本
echo "当前时间是 " . date("h:i:sa");
$sql = "select * from `{$tabName}` ";
if (!$obj = mysqli_query($con, $sql)) {
    die(mysqli_error($con) . $sql);
    //字段已经存在 会报错加不上去但是不用管
}
$data = array();
while ($RESULT = mysqli_fetch_assoc($obj)) {
    $data[] = $RESULT;

}
$time = 0;
echo "当前时间是 " . date("h:i:sa");
$count = 0;
foreach ($data as $value) {

    $id = $value['id'];
    if (empty($value['bdy_content'])) {
        $count++;
        $file_dir = str_replace('www.liuan.mobi', LA_WEBSITE, $value['pay_dir']);
        $file_dir = str_replace('www.ywlzy.com', LA_WEBSITE, $file_dir);
        $file_dir = str_replace('http://', '', $file_dir);
        $file_dir = str_replace('https://', '', $file_dir);
//根据当前网络环境自适应
        $bdy_res = file_get_contents((isHTTPS() ? 'https://' : 'http://') . $file_dir);
//    $bdy_res=str_replace("`", '\`', $bdy_res);
        $bdy_res = str_replace("`", "\`", $bdy_res);
        $bdy_res = str_replace("'", "\'", $bdy_res);

        $sql = "UPDATE `{$tabName}` set `bdy_content`='{$bdy_res}' where `id`='{$id}' ";
        if (!$obj = mysqli_query($con, $sql)) {
            die(mysqli_error($con) . $sql);
            //字段已经存在 会报错加不上去但是不用管
        }
    } else {
        echo $id . "处理完毕";
        echo "当前时间是 " . date("h:i:sa");
    }

猜你喜欢

转载自blog.csdn.net/mp624183768/article/details/88216352