正确解读PHP应用odbc技巧

开发 后端
PHP应用odbc乐意帮助我们进行ACESS数据库的操作。对于新手来说对于这一操作步骤应该还不是太清楚。希望通过本文介绍的知识能够充分掌握这一技巧。

当我们在应用PHP语言对ACCESS数据库操作时,通常都会用到PHP中的odbc。下面我们就来具体认识一下PHP应用odbc是如何操作ACCESS数据库的。#t#

PHP应用odbc具体代码:

  1. class odbc_db  
  2. {  
  3. var $con = null;  
  4. var $resource = null;  
  5. function __construct()  
  6. {  
  7. }  
  8. function connect($dsn = ” , 
    $
    user = ” , $passwd = ” , 
    $
    cursor_type = 0)  
  9. {  
  10. !$dsn && $this->debug(’dsn not provided!’);  
  11. $this->con = odbc_connect($dsn ,$user 
    , $passwd ,$cursor_type);  
  12. !$this->con && $this->debug(’conncet failed!’);  
  13. return $this->con;  
  14. }  
  15. function query($sql = ”)  
  16. {  
  17. $this->resource = odbc_exec($this->con , $sql);  
  18. !$this->resource && $this->debug
    (’query failed!’);  
  19. return $this->resource;  
  20. }  
  21. function fetch_array($resource = ”)  
  22. {  
  23. !$resource && $resource = $this->resource;  
  24. return odbc_fetch_array($resource);  
  25. }  
  26. function query_first($sql = ”)  
  27. {  
  28. $resource = $this->query($sql);  
  29. return odbc_fetch_array($resource);  
  30. }  
  31. function fetch_all($resource = ”)  
  32. {  
  33. !$resource && $resource = $this->resource;  
  34. $results = array();  
  35. while(false !== ($row = @odbc_fetch_
    array($resource)))  
  36. {  
  37. $results[] = $row;  
  38. }  
  39. return $results;  
  40. }  
  41. function num_rows()  
  42. {  
  43. return odbc_num_rows($this->con);  
  44. }  
  45. function affected_rows()  
  46. {  
  47. return odbc_num_rows($this->con);  
  48. }  
  49. function debug($message = ”)  
  50. {  
  51. $message .= ‘  
  52. 以下错误信息由ODBC 提供:’. odbc_errormsg();  
  53. exit($message);  
  54. }  
  55. function __destruct()  
  56. {  
  57. odbc_close($this->con);  
  58. }  
  59. }  
  60. ?> 

以上就是PHP应用odbc的全部方法步骤,希望对大家有所帮助。

责任编辑:曹凯 来源: realized.cn
相关推荐

2009-12-11 16:44:33

PHP冒泡排序

2009-12-09 14:25:21

PHP获取时间错误

2009-12-10 17:54:57

PHP删除Cookie

2009-12-07 18:57:17

PHP读取Cookie

2009-12-04 14:09:52

PHP JSON应用

2009-12-04 15:43:03

PHP JSON扩展

2009-12-10 09:48:26

PHP获取远程图片

2009-12-08 14:11:03

PHP时区修改

2009-12-07 14:38:14

PHP foreach

2009-12-08 16:48:25

PHP类phpExce

2009-12-11 15:35:50

PHP弹出对话框

2009-12-11 17:57:13

PHP应用JSON

2009-11-26 09:06:35

PHP递归数组

2009-11-17 11:24:00

PHP应用技巧

2009-11-18 18:24:26

PHP模板

2009-12-08 09:51:10

PHP intval函

2009-12-11 10:59:48

PHP函数extrac

2010-02-26 10:46:12

WCF行为扩展

2010-03-01 16:04:31

WCF服务契约

2009-12-07 14:53:13

PHP抽象类应用
点赞
收藏

51CTO技术栈公众号