正確解讀PHP應(yīng)用odbc技巧
作者:佚名
PHP應(yīng)用odbc樂意幫助我們進(jìn)行ACESS數(shù)據(jù)庫的操作。對于新手來說對于這一操作步驟應(yīng)該還不是太清楚。希望通過本文介紹的知識能夠充分掌握這一技巧。
當(dāng)我們在應(yīng)用PHP語言對ACCESS數(shù)據(jù)庫操作時(shí),通常都會用到PHP中的odbc。下面我們就來具體認(rèn)識一下PHP應(yīng)用odbc是如何操作ACCESS數(shù)據(jù)庫的。#t#
PHP應(yīng)用odbc具體代碼:
- class odbc_db
- {
- var $con = null;
- var $resource = null;
- function __construct()
- {
- }
- function connect($dsn = ” ,
$user = ” , $passwd = ” ,
$cursor_type = 0) - {
- !$dsn && $this->debug(’dsn not provided!’);
- $this->con = odbc_connect($dsn ,$user
, $passwd ,$cursor_type); - !$this->con && $this->debug(’conncet failed!’);
- return $this->con;
- }
- function query($sql = ”)
- {
- $this->resource = odbc_exec($this->con , $sql);
- !$this->resource && $this->debug
(’query failed!’); - return $this->resource;
- }
- function fetch_array($resource = ”)
- {
- !$resource && $resource = $this->resource;
- return odbc_fetch_array($resource);
- }
- function query_first($sql = ”)
- {
- $resource = $this->query($sql);
- return odbc_fetch_array($resource);
- }
- function fetch_all($resource = ”)
- {
- !$resource && $resource = $this->resource;
- $results = array();
- while(false !== ($row = @odbc_fetch_
array($resource))) - {
- $results[] = $row;
- }
- return $results;
- }
- function num_rows()
- {
- return odbc_num_rows($this->con);
- }
- function affected_rows()
- {
- return odbc_num_rows($this->con);
- }
- function debug($message = ”)
- {
- $message .= ‘
- 以下錯(cuò)誤信息由ODBC 提供:’. odbc_errormsg();
- exit($message);
- }
- function __destruct()
- {
- odbc_close($this->con);
- }
- }
- ?>
以上就是PHP應(yīng)用odbc的全部方法步驟,希望對大家有所幫助。
責(zé)任編輯:曹凱
來源:
realized.cn