php sql 读取写入操作数据库
时间:2023年10月05日
/来源:网络
/编辑:佚名
即将学习面向对象,所以呢,一些代码需要删除,这里做一下记录
这串代码主要用于帝国数据库的写入操作等等
<?php
// header('content-type:text/html;charset=utf-8;');
// header('content-type:application/json;charset=utf-8');
define('DB_NAME', 'rming');
define('DB_USER', 'rming');
define('DB_PASSWORD', 'Px6nCaaYESbMHmST');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_PREFIX', 'phome_');
// 检测连接
if (!$conn = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)) {
die("<b>PHP链接MYSQL数据库出现错误!请检查配置!</b>");
}
//选择数据库
if(!mysqli_select_db($conn,DB_NAME)){
die("<b>PHP选择MYSQL数据库出现错误!请检查配置!</b>");
}
$pages = 300;
//设置字符集
mysqli_set_charset($conn,DB_CHARSET);
$id = $_GET['id']-1;
//执行SQL语句
$select = mysqli_query($conn,'SELECT * FROM `phome_author` ORDER BY `id` ASC limit '.$pages*$id.','.$pages.'');
$where = '';
while($arr = mysqli_fetch_array($select)){
$where .= "(NULL, '$arr[booker]', '', '')".',';
}
$where = rtrim($where,',');
$where = "INSERT INTO `phome_booker` (`id`, `booker`, `bookerurl`, `bookid`) VALUES " . $where;
echo $where;
// $arr = mysqli_fetch_all($select,MYSQLI_ASSOC);
// print_r(json_encode($arr));
//
//关闭数据库
mysqli_close($conn);
这串代码主要用于帝国数据库的写入操作等等
<?php
// header('content-type:text/html;charset=utf-8;');
// header('content-type:application/json;charset=utf-8');
define('DB_NAME', 'rming');
define('DB_USER', 'rming');
define('DB_PASSWORD', 'Px6nCaaYESbMHmST');
define('DB_HOST', 'localhost');
define('DB_CHARSET', 'utf8');
define('DB_PREFIX', 'phome_');
// 检测连接
if (!$conn = @mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)) {
die("<b>PHP链接MYSQL数据库出现错误!请检查配置!</b>");
}
//选择数据库
if(!mysqli_select_db($conn,DB_NAME)){
die("<b>PHP选择MYSQL数据库出现错误!请检查配置!</b>");
}
$pages = 300;
//设置字符集
mysqli_set_charset($conn,DB_CHARSET);
$id = $_GET['id']-1;
//执行SQL语句
$select = mysqli_query($conn,'SELECT * FROM `phome_author` ORDER BY `id` ASC limit '.$pages*$id.','.$pages.'');
$where = '';
while($arr = mysqli_fetch_array($select)){
$where .= "(NULL, '$arr[booker]', '', '')".',';
}
$where = rtrim($where,',');
$where = "INSERT INTO `phome_booker` (`id`, `booker`, `bookerurl`, `bookid`) VALUES " . $where;
echo $where;
// $arr = mysqli_fetch_all($select,MYSQLI_ASSOC);
// print_r(json_encode($arr));
//
//关闭数据库
mysqli_close($conn);
新闻资讯 更多
- 【建站知识】查询nginx日志状态码大于400的请求并打印整行04-03
- 【建站知识】Python中的logger和handler到底是个什么?04-03
- 【建站知识】python3拉勾网爬虫之(您操作太频繁,请稍后访问)04-03
- 【建站知识】xpath 获取meta里的keywords及description的方法04-03
- 【建站知识】python向上取整以50为界04-03
- 【建站知识】scrapy xpath遇见乱码解决04-03
- 【建站知识】scrapy爬取后中文乱码,解决word转为html 时cp1252编码问题04-03
- 【建站知识】scrapy采集—爬取中文乱码,gb2312转为utf-804-03