温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP如何应用odbc技巧

发布时间:2021-10-18 17:05:44 来源:亿速云 阅读:86 作者:柒染 栏目:编程语言

PHP如何应用odbc技巧,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

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

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. ?> 

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI