conndb.php
<?php
$link=mysqli_connect('localhost','root','password','database');//连接数据库
mysqli_select_db($link,"database");//选择数据库
mysqli_query($link,'set name gb2312');
?>
index.php
require('conndb.php');
$sql="select * from aa03 where aaa301=1";//
$result=mysqli_query($link,$sql);//执行sql语句
if ($result instanceof mysqli_result)
{
while ( $row = $result->fetch_object() )
{
$company_c01= $row->aaa302;
$company_c02= $row->aaa303;
$company_c03= $row->aaa304;
}
}
通过require(); 引入连接数据库信息,然后查询数据库输出相应内容。这是我最近做的一个门户网站,后台查询数据库提取内容的代码,我感觉不太方便的内容就是后面提取字段值的时候,应该有其他办法吧,我这样用着也不是不行就是感觉不方便。