PHP操作指纹机access数据库小记(初步设想)
2011-10-15
904
简介:
基地购置了指纹考勤机,昨天打扫卫生又杀虫子,这东西试了两下也没研究明白,今天十年梦生忙我搞定,并破译了考勤机数据库密码。其实这东西也不是他们自行开发的,起码软件的数据库内容都是从国外的同类东西,把部分汉化过来的,可以看到数据库中有很多表都是全英文的信息。
基地购置了指纹考勤机,昨天打扫卫生又杀虫子,这东西试了两下也没研究明白,今天十年梦生忙我搞定,并破译了考勤机数据库密码。其实这东西也不是他们自行开发的,起码软件的数据库内容都是从国外的同类东西,把部分汉化过来的,可以看到数据库中有很多表都是全英文的信息。

虽然考勤机自带的软件功能不错了,但为了定制,所以如果想开发出针对领导只看到按日期的员工出勤的统计报表的话,那就只有自己研究数据库并自己写代码了。
以前没做过PHP访问access数据的东西,这次碰到,搜了一下,发现一篇博文记录了一个access数据库访问类,不错,摘录下来。
- ?php
-
class db_access
-
{
-
var $querynum = 0;
-
var $conn;
-
var $insertid = 0;
-
var $cursor = 0;
-
-
function connect($dbhost, $dbuser = '', $dbpw = '', $dbname = '', $pconnect = 0)
-
{
-
$this->conn = new com('adodb.connection');
-
if(!$this->conn) return false;
-
// or exit('Cannot start ADO');
-
$this->conn->open("DRIVER={Microsoft Access Driver (*.mdb)};dbq=$dbhost;uid=$dbuser;pwd=$dbpw");
-
if($this->conn->state == 0)
-
{
-
$this->conn->open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$dbhost");
-
if($this->conn->state == 0) return false;;
-
}
-
define('NUM', 1);
-
define('ASSOC', 2);
-
define('BOTH', 3);
-
return $this->conn->state;
-
}
-
-
-
function select_db($dbname)
-
{
-
return $this->conn->state;
-
}
-
-
function query($sql, $type = '', $expires = 3600, $dbname = '')
-
{
-
$this->querynum++;
-
$sql = trim($sql);
-
if(preg_match("/^(select.*)limit ([0-9]+)(,([0-9]+))?$/i", $sql, $matchs))
-
{
-
$sql = $matchs[1];
-
$offset = $matchs[2];
-
$pagesize = $matchs[4];
-
$query = $this->conn->Execute($sql);
-
return $this->limit($query, $offset, $pagesize);
-
}
-
else
-
{
-
return $this->conn->Execute($sql);
-
}
-
}
-
-
function get_one($query)
-
{
-
$this->querynum++;
-
$rs = $this->conn->Execute($query);
-
$r = $this->fetch_array($rs);
-
$this->free_result($rs);
-
return $r;
-
}
-
-
function fetch_array($rs, $result_type = 3)
-
{
-
if(is_array($rs))
-
{
-
return $this->cursor count($rs) ? $rs[$this->cursor++] : FALSE;
-
}
-
else
-
{
-
if($rs->EOF) return FALSE;
-
$array = array();
-
for($i = 0; $i $this->num_fields($rs); $i++)
-
{
-
$fielddata = $rs->Fields[$i]->Value;
-
if($result_type == NUM || $result_type == BOTH) $array[$i] = $fielddata;
-
if($result_type == ASSOC || $result_type == BOTH) $array[$rs->Fields[$i]->Name] = $fielddata;
-
}
-
$rs->MoveNext();
-
return $array;
-
}
-
}
-
-
function select($sql, $keyfield = '')
-
{
-
$array = array();
-
$result = $this->query($sql);
-
while($r = $this->fetch_array($result))
-
{
-
if($keyfield)
-
{
-
$key = $r[$keyfield];
-
$array[$key] = $r;
-
}
-
else
-
{
-
$array[] = $r;
-
}
-
}
-
$this->free_result($result);
-
return $array;
-
}
-
-
function num_rows($rs)
-
{
-
return is_array($rs) ? count($rs) : $rs->recordcount;
-
}
-
-
function num_fields($rs)
-
{
-
return $rs->Fields->Count;
-
}
-
-
function fetch_assoc($rs)
-
{
-
return $this->fetch_array($rs, ASSOC);
-
}
-
-
function fetch_row($rs)
-
{
-
return $this->fetch_array($rs, NUM);
-
}
-
-
function free_result($rs)
-
{
-
if(is_resource($rs)) $rs->close();
-
}
-
-
function error()
-
{
-
return $this->conn->Errors[$this->conn->Errors->Count-1]->Number;
-
}
-
-
function errormsg()
-
{
-
return $this->conn->Errors[$this->conn->Errors->Count-1]->Description;
-
}
-
-
function close()
-
{
-
$this->conn->close();
-
}
-
-
function limit($rs, $offset, $pagesize = 0)
-
{
-
if($pagesize > 0)
-
{
-
$rs->Move($offset);
-
}
-
else
-
{
-
$pagesize = $offset;
-
}
-
$info = array();
-
for($i = 0; $i $pagesize; $i++)
-
{
-
$r = $this->fetch_array($rs);
-
if(!$r) break;
-
$info[] = $r;
-
}
-
$this->free_result($rs);
-
$this->cursor = 0;
-
return $info;
-
}
-
}
-
?>
进一步还有例子:(感谢
http://www.iteye.com/topic/815536)
- ?php
-
define('ACC_ROOT', str_replace("\\", '/', dirname(__FILE__)).'/');//定义本程序根路径
-
define('DB_HOST',ACC_ROOT.'#%201f9558a613f476d0d591.mdb');//定义access存放路径
-
include(ACC_ROOT.'access/db_access.class.php');//载入access类库
-
$blogdb = new db_access;//实例化
-
$blogdb->connect(DB_HOST, DB_USER, DB_PW, DB_NAME, DB_PCONNECT, DB_CHARSET);//开启access链接
-
$execarr = array();
-
$sqlblog = $blogdb->query("select log_ID,log_Title,log_Intro,log_PostTime,log_CateID from blog_Article order by log_PostTime DESC limit 0,5");
-
while($arrblog = $blogdb->fetch_array($sqlblog))
-
{
-
$execarr[] = $arrblog;
-
}
-
$cat = array(3=>'easay',4=>'video',5=>'bridalveil',6=>'activity',8=>'photo',9=>'media',10=>'wedding');//定义url链接目录
-
$ext = 'gif|jpg|jpeg|bmp|png';//罗列图片后缀从而实现多扩展名匹配
-
foreach($execarr AS $k=>$v)
-
{
-
preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))\\2/i", $v['log_Intro'], $matches);
-
$imgsrc = 'http://www.k686.com/'.str_replace('upload','attachments',$matches[3][0]);
-
echo '
- .$cat[$v['log_CateID']].'/'.$v['log_ID'].'.html" target="_blank">
-
.$imgsrc.'" width="87" height="58" />
-
'.$v['log_Title'].'
-
POST TIME:'.$v['log_PostTime'].'
'
;}?>
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。