Mercurial > defr > DualBlog
comparison includes/class.dataaccess.php @ 81:e4e50d4d3b7a
DataAccess: Passage en mysqli
| author | Franck Deroche <franck@defr.org> |
|---|---|
| date | Tue, 20 Nov 2018 00:53:47 +0100 |
| parents | 0071e5744311 |
| children | d49afe579884 249de0d66f8c |
comparison
equal
deleted
inserted
replaced
| 80:b6ea01331de2 | 81:e4e50d4d3b7a |
|---|---|
| 16 $this->user=$user; | 16 $this->user=$user; |
| 17 $this->pass=$pass; | 17 $this->pass=$pass; |
| 18 $this->db = $db; | 18 $this->db = $db; |
| 19 $this->connOpen = 0; | 19 $this->connOpen = 0; |
| 20 $this->_nbQueries = 0; | 20 $this->_nbQueries = 0; |
| 21 $this->_inError = false; | |
| 21 $this->queries = array(); | 22 $this->queries = array(); |
| 22 $this->results = array(); | 23 $this->results = array(); |
| 23 $this->Connect(); | 24 $this->Connect(); |
| 24 } | 25 } |
| 25 | 26 |
| 26 function Connect() { | 27 function Connect() { |
| 27 if($this->connOpen == 0) { | 28 if($this->connOpen == 0) { |
| 28 $this->link = mysql_connect($this->host, $this->user, $this->pass); | 29 $this->link = mysqli_connect($this->host, $this->user, $this->pass, $this->db); |
| 29 if($this->link === false) | 30 if($this->link === false) |
| 30 $this->_inError = true; | 31 $this->_inError = true; |
| 31 else | 32 else |
| 32 $this->_inError = !mysql_select_db($this->db, $this->link); | 33 mysqli_set_charset($this->link, 'utf8'); |
| 33 } | 34 } |
| 34 $this->connOpen++; | 35 $this->connOpen++; |
| 35 } | 36 } |
| 36 | 37 |
| 37 function Query($query, $id=0) { | 38 function Query($query, $id=0) { |
| 38 $this->_nbQueries++; | 39 $this->_nbQueries++; |
| 39 $this->queries[$id]=$query; | 40 $this->queries[$id]=$query; |
| 40 $this->Connect(); | 41 $this->Connect(); |
| 41 $this->results[$id]=mysql_query($this->queries[$id], $this->link); | 42 $this->results[$id]=mysqli_query($this->link, $this->queries[$id]); |
| 42 $this->Close(); | 43 $this->Close(); |
| 43 if(@$num_rows=mysql_num_rows($this->results[$id])) | 44 if(@$num_rows=mysqli_num_rows($this->results[$id])) |
| 44 return $num_rows; | 45 return $num_rows; |
| 45 return 0; | 46 return 0; |
| 46 } | 47 } |
| 47 | 48 |
| 48 function debugQuery($query, $id=0) { | 49 function debugQuery($query, $id=0) { |
| 51 echo("<span class='menu'>\n Query : {$query}<br />\n MySQL Answer : " . mysql_error() . "</span>"); | 52 echo("<span class='menu'>\n Query : {$query}<br />\n MySQL Answer : " . mysql_error() . "</span>"); |
| 52 return $rv; | 53 return $rv; |
| 53 } | 54 } |
| 54 | 55 |
| 55 function GetRow($id=0) { | 56 function GetRow($id=0) { |
| 56 if(@$row=mysql_fetch_array($this->results[$id])) { | 57 if(@$row=mysqli_fetch_array($this->results[$id])) { |
| 57 return $row; | 58 return $row; |
| 58 } | 59 } |
| 59 return 0; | 60 return 0; |
| 60 } | 61 } |
| 61 | 62 |
| 62 function Close() { | 63 function Close() { |
| 63 $this->connOpen--; | 64 $this->connOpen--; |
| 64 if($this->connOpen == 0) { | 65 if($this->connOpen == 0) { |
| 65 mysql_close($this->link); | 66 mysqli_close($this->link); |
| 66 } | 67 } |
| 67 } | 68 } |
| 68 | 69 |
| 69 function getNbQueries() { | 70 function getNbQueries() { |
| 70 return $this->_nbQueries; | 71 return $this->_nbQueries; |
