代码拉取完成,页面将自动刷新
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2017/3/3
* Time: 15:21
*
*
*/
function LendBook(){
echo "请您输入书号:";
$book_id = trim(fgets(STDIN));
echo "请输入学号:";
$number = trim(fgets(STDIN));
echo "请输入您的姓名:";
$reader_name = trim(fgets(STDIN));
echo "请输入书名:";
$book_name = trim(fgets(STDIN));
//连接数据库
$dsn = 'mysql:dbname=school;host=192.168.137.2';
$user = 'root';
$password = '123456';
$db = new PDO($dsn, $user, $password);
try {
$aaa = $db->exec("insert into record (rid,bid,rname,bname)VALUES
('$number','$book_id','$reader_name','$book_name')");
if ($aaa) {
echo "语句对了\n";
} else if ($aaa === false) {
echo "语句出错\n";
} else {
echo "内容为空,请联系管理员:110\n";
}
} catch (PDOException $e) {
echo 'Connection failed:' . $e->getMessage();
echo "\n";
}
//显示结果
$aaa = ($db->query("select * from record"));
$temp = $aaa->fetchAll(PDO::FETCH_ASSOC);
print_r($temp);
//借书时限为一个月
$borrowTime = date('Y-m-d');
$backTime = date("Y-m-d", (time() + 3600 * 24 * 30));
echo "借书成功,请于" . $backTime . "内归还!\n";
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。