现在的位置: 首页 > 综合 > 正文

php连接数据库,日期截取

2014年08月29日 ⁄ 综合 ⁄ 共 572字 ⁄ 字号 评论关闭

co.php:

function hh(){
 $conn = new com("ADODB.Connection");
 $connstr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" . realpath("#database#/#database#.mdb ");
 $conn->Open($connstr);
return $conn;
}

<?php
include "inc/co.php";
$conn=hh();
?>

 

日期:

$newstime=$rs->Fields("newstime");
echo date("Y/m/d",strtotime($newstime));

 

读取数据:

<?php
$rs=new com("adodb.recordset");
$sql="select * from news where news_class_id=14 order by newstime desc";
$rs->Open($sql,$conn,1,1);
if (!$rs->eof){
 for($i=0;$i<=6;$i++){
  ?>

<?=$rs->Fields("newstitle") ?>

 

  <?php
  $rs->movenext;
  if($rs->eof){
  break;
  }
 }
}
$rs->close;
$rs=null;
?>

抱歉!评论已关闭.