php原生链接mysql,并读取数据

admin3年前PHP803
<?php
header("Content-type:text/html;charset=utf-8");
set_time_limit(0);

//连接数据库
$con = mysqli_connect("localhost", "root", "root", "dyfilmold");
if (!$con) {
    die('Could not connect: ' . mysqli_error());
}
mysqli_query($con, 'SET NAMES UTF8');

$numsQuery = mysqli_query($con, "select count(*) from ay_content where scode = 1");
$numsQuery2 = mysqli_fetch_row($numsQuery);
$nums = $numsQuery2[0];

$page = intval($_GET['page']);if(empty($page)) $page=1;
$nextpage = $page+1;
$pagesize = 100;

$pages = ceil($nums/$pagesize);
$firstR = ($page-1)*$pagesize;

//连接数据库
$con2 = mysqli_connect("localhost", "root", "root", "dyfilm");
if (!$con2) {
    die('Could not connect: ' . mysqli_error());
}
mysqli_query($con2, 'SET NAMES UTF8');



$r = mysqli_query($con, "select * from ay_content where scode = 1 order by id desc limit $firstR,$pagesize");
while($v = mysqli_fetch_assoc($r)){
    $aid = $v['id'];
    $title = addslashes($v['title']);
    $content = str_replace(['2023-02-27'], ['/2023-02-27'], addslashes($v['content']));
    $seo_title = '';
    $seo_keywords = addslashes($v['keywords']);
    $seo_description = addslashes($v['description']);
    $litpic = '';
    $lx = addslashes(trim($v['lx']));
    $dw = addslashes(trim($v['dw']));
    $author = addslashes(trim($v['author']));
    $source = addslashes(trim($v['source']));
    $sort_order = intval(trim($v['sorting']));
    $add_time = strtotime(trim($v['create_time']));
    $update_time = strtotime(trim($v['update_time']));
    $click = intval($v['visits']);

    $sql = "insert into dyfilm_archives(aid,typeid,title,channel,is_litpic,litpic,click,arcrank,seo_title,seo_keywords,seo_description,sort_order,lang,add_time,update_time,author,origin) values($aid, 1, '".$title."', 1, 0, '', $click, 0, '$seo_title','$seo_keywords','$seo_description','1000','cn','$add_time','$update_time','$author','$source');";


    $rs = mysqli_query($con2, $sql);
    if (!$rs) {
        die($sql);
    }

    $sql = "insert into dyfilm_article_content(aid,content,add_time,update_time) values($aid,'$content','$add_time','$add_time')";
    mysqli_query($con2, $sql);


}
if($nextpage <= $pages){
    $url = '?page='.$nextpage;
    echo '<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"></head><body><script>window.setTimeout(function(){window.location.href="'.$url.'"}, 1000)</script></body></html>';
}else{
    exit('已完成');
}

?>


相关文章

宝塔面板无法执行composer命令

请选择root用户执行...

php切片上传

html    <style>        html {...

阿里云虚拟电话保护

下载安装好compser下载DEMO,参考网址https://next.api.aliyun.com/api/Dyplsapi/2017-05-25/BindAxb?spm=a2c4g.1118662...

opencart教程 上传产品

opencart教程 上传产品

点击左边导航【商品目录】【商品管理】点击右上角加号,新增商品填写数据时,以下是必填分类选择如下...

phpqrcode生成二维码,并在底部加上图片

Vendor('phpqrcode.phpqrcode');$font = ROOT_PATH.'public/static/common/font/hgzb.ttf'...

redis

进入CMD命令进入相应redis目录cd redisredis-server.exe redis.windows.conf...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。