php sql 读取写入操作数据库

即将学习面向对象,所以呢,一些代码需要删除,这里做一下记录
这串代码主要用于帝国数据库的写入操作等等

<?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);

© 版权声明
THE END
喜欢就支持一下吧
点赞15
评论 抢沙发

请登录后发表评论

    暂无评论内容