class SqlHelper{
public $mysqli;
public $dbname="db_tmlog";
public $username="root";
public $password="root";
public $host="localhost";
public function __construct(){
$this->mysqli = new mysqli($this->host, $this->username, $this->password, $this->dbname);
if($this->mysqli->connect_error){
die("连接失败".$this->mysqli->connect_error);
}
$this->mysqli->query("set names utf8");
}
//执行dql语句
public function execute_dql($sql){
$res = $this->mysqli->query($sql) or die($this->mysqli->error);
//这里返回的是一个结果集,当调用$row = $res->fetch_assoc()时是一条一条的向下走,应该使用while循环
return $res;
} }
dql语句就是简单的查询语句。
在使用数据库查询之前,先把这个文件包进去,然后new一个工具类对象,然后使用对象调用里面的函数。
3、最新图片显示
$sql="select id,tpmc,file from tb_tpsc order by id desc limit 2";
$res2 = $sqlHelper->execute_dql($sql);
while($info=$res2->fetch_assoc()){
$query="select * from tb_tpsc where id=".$info['id'];
$result=$sqlHelper->execute_dql($query);
if($row = $result->fetch_assoc()){
$data = $row['file'];
}
?>
" target="_blank">
图片名称:
同样使用了数据库查询。
4、公告区实现
在公告区使用了我以前没有见过的一个标签
它里面设置了一些属性,就是当鼠标停留在上面的时候它就停止滚动,离开的时候就开始滚动。
$p_sql = "select * from tb_public order by id desc";
$p_rst = $sqlHelper->execute_dql($p_sql);
?>
这个标签是HTML5新增的,还有center标签。那么在使用的时候就会出现下面画黄色波浪线的情况,我没有去管他。