PHP头条
热点:

正确解读PHP应用odbc技巧


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

  • 如何运用PHP函数pack处理资料
  • 分享PHP unpack函数解压缩位字符串实现技
  • 深入解读PHP类phpExcel应用
  • PHP PEAR DB类在网站建设中的作用体现
  • PHP PEAR DB类函数总结一览

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的全部方法步骤,希望对大家有所帮助。

www.phpzy.comtrue/php/12081.htmlTechArticle正确解读PHP应用odbc技巧 当我们在应用PHP语言对ACCESS数据库操作时,通常都会用到PHP中的odbc。下面我们就来具体认识一下PHP应用odbc是如何操作ACCESS数据库的。 如何运用PHP函数pack处理资...

相关文章

    暂无相关文章
相关频道:

PHP之友评论

今天推荐