php原生链接mysql,并读取数据
<?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('已完成');
}
?>