正确解读PHP应用odbc技巧_PHP教程
程序员文章站
2022-06-17 15:01:40
...
当我们在应用
PHP应用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 .= ‘
- 以下错误信息由ODBC 提供:’. odbc_errormsg();
- exit($message);
- }
- function __destruct()
- {
- odbc_close($this->con);
- }
- }
- ?>
以上就是PHP应用odbc的全部方法步骤,希望对大家有所帮助。