PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/PDOConfig.php

https://bitbucket.org/mageecprojects/portail3g
PHP | 117 lines | 86 code | 23 blank | 8 comment | 11 complexity | b2de4fa7d2fe8bab8002c3fa6b73e4ab MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. *
  4. *
  5. * @version $Id$
  6. * @copyright 2010
  7. */
  8. class PDOConfig extends PDO {
  9. private $engine;
  10. private $host;
  11. private $database;
  12. private $user;
  13. private $pass;
  14. public function __construct($lengine,$lhost,$ldatabase,$luser,$lpass){
  15. $this->engine = $lengine;
  16. $this->host = $lhost;
  17. $this->database = $ldatabase;
  18. $this->user = $luser;
  19. $this->pass = $lpass;
  20. $dns = $this->engine.':dbname='.$this->database.";host=".$this->host;
  21. parent::__construct( $dns, $this->user, $this->pass );
  22. $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  23. }
  24. public function _query($sql){
  25. $list=$this->prepare($sql);
  26. $list->execute();
  27. $result=$list->fetchAll(PDO::FETCH_ASSOC);
  28. $list->closeCursor();
  29. return $result;
  30. }
  31. //--------------------------
  32. public function _queryOne($sql){
  33. $list=$this->prepare($sql);
  34. $list->execute();
  35. $result=$list->fetch(PDO::FETCH_ASSOC);
  36. $list->closeCursor();
  37. if(empty($result)) $result=array();
  38. return $result;
  39. }
  40. //--------------------------
  41. public function executeRequete($sql,$debug=0){
  42. try{
  43. $list=$this->prepare($sql);
  44. $list->execute();
  45. $result=$list->fetchAll(PDO::FETCH_ASSOC);
  46. $list->closeCursor();
  47. }catch (PDOException $e){
  48. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  49. echo "reket=".$sql."<br>retour=".$e->getMessage();
  50. }
  51. }
  52. if($debug==1){
  53. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  54. echo "reket=".$sql."<br>retour=".print_r($result,true);
  55. }
  56. }
  57. return $result;
  58. }
  59. public function execCustom($sql,$debug=0){
  60. try{
  61. $result=$this->exec($sql);
  62. }catch(PDOException $e){
  63. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  64. echo "reket=".$sql."<br>retour=".$e->getMessage();
  65. }
  66. }
  67. if($debug==1){
  68. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  69. echo "reket=".$sql."<br>retour=".print_r($result,true);
  70. }
  71. }
  72. }
  73. public function executeOne($sql,$debug=0){
  74. $error="";
  75. try{
  76. $list=$this->prepare($sql);
  77. $list->execute();
  78. $result=$list->fetch(PDO::FETCH_ASSOC);
  79. $list->closeCursor();
  80. if(empty($result)) $result=array();
  81. }catch(PDOException $e){
  82. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  83. echo "reket=".$sql."<br>retour=".$e->getMessage();
  84. }
  85. }
  86. if($debug==1){
  87. if(getenv("APPLICATION_ENV")!="PRODUCTION"){
  88. echo "reket=".$sql."<br>retour=".print_r($result,true);
  89. }
  90. }
  91. return $result;
  92. }
  93. }
  94. ?>