Pomoc - Szukaj - U¿ytkownicy - Kalendarz
Pe³na wersja: [php]Problem z MysqlException
Forum PHP.pl > Forum > Przedszkole
Virnel
Witam!

Jestem do¶æ nowy w pHp i mam taki problem. Kiedy parser przechodzi przez ten skrypt dostajê nastêpuj±cy komunikat:

Fatal error: Class 'MysqlException' not found in /dokumentacja/lib/db.php on line 142

Szuka³em pomocy w manualach i na forum, ale niestety nic nie znalaz³em. Bêdê bardzo wdziêczny za wszelk± pomoc. Liczba 142 w kodzie oznacza oczywi¶cie numer wiersza z komunikatu o b³êdzie.

  1. <?php
  2.  
  3. //-----------Polaczenie z bazÄ…--------------
  4. interface DB_Connection {
  5. public function prepare($query);
  6. public function execute($query);
  7. }
  8.  
  9.  
  10. interface DB_Statement {
  11. public function execute();
  12. public function bind_param($key, $value);
  13. public function fetch_row();
  14. public function fetch_assoc();
  15. public function fetchall_assoc();
  16. }
  17.  
  18. //--------Mysql--------------------------
  19. class DB_Mysql implements DB_Connection {
  20. protected $user;
  21. protected $pass;
  22. protected $dbhost;
  23. protected $dbname;
  24. protected $dbh;
  25.  
  26. public function __construct($user, $pass, $dbhost, $dbname) {
  27. $this->user = $user;
  28. $this->pass = $pass;
  29. $this->dbhost = $dbhost;
  30. $this->dbname = $dbname;
  31. }
  32. protected function connect() {
  33. $this->dbh = mysql_pconnect($this->dbhost, $this->user, $this->pass);
  34. if(!is_resource($this->dbh)) {
  35. throw new MysqlException;
  36. }
  37. if(!mysql_select_db($this->dbname, $this->dbh)) {
  38. throw new MysqlException;
  39. }
  40. }
  41. public function execute($query) {
  42. if(!$this->dbh) {
  43. $this->connect();
  44. }
  45. $ret = mysql_query($query, $this->dbh); 
  46. if(!$ret) {
  47. throw new MysqlException;
  48. }
  49. else if(!is_resource($ret)) {
  50. return TRUE;
  51. } else {
  52. $stmt = new DB_MysqlStatement($this->dbh, $query);
  53. $stmt->result = $ret;
  54. return $stmt;
  55. }
  56. }
  57. public function prepare($query) {
  58. if(!$this->dbh) {
  59. $this->connect();
  60. }
  61. return new DB_MysqlStatement($this->dbh, $query);
  62. }
  63. }
  64.  
  65. class DB_MysqlStatement implements DB_Statement {
  66. public $result;
  67. public $binds;
  68. public $query;
  69. public $dbh;
  70. public function __construct($dbh, $query) {
  71. $this->query = $query;
  72. $this->dbh = $dbh;
  73. if(!is_resource($dbh)) {
  74. throw new MysqlException("NieprawidÅ‚owe połączenie do bazy danych");
  75. }
  76. }
  77.  
  78. public function bind_param($ph, $pv) {
  79. $this->binds[$ph] = $pv;
  80. return $this;
  81. }
  82.  
  83. public function execute() {
  84. $binds = func_get_args();
  85. foreach ($binds as $index => $name) {
  86. $this->binds[$index + 1] = $name;
  87. }
  88. $query = $this->query;
  89. $cnt = count($binds);
  90. if (isset($this->binds)){
  91. foreach ($this->binds as $ph => $pv) {
  92. $query = str_replace(":$ph", "'".mysql_escape_string($pv)."'", $query);
  93. }
  94. }
  95. $this->result = mysql_query($query, $this->dbh);
  96. if(!$this->result) {
  97. throw new MysqlException;
  98. }
  99. return $this;
  100. }
  101.  
  102. public function fetch_row() {
  103. if(!$this->result) {
  104. throw new MysqlException("Zapytanie nie zostaÅ‚o wykonane");
  105. }
  106. return mysql_fetch_row($this->result);
  107. }
  108.  
  109. public function fetch_assoc() {
  110. return mysql_fetch_assoc($this->result);
  111. }
  112.  
  113. public function fetchall_assoc() {
  114. $retval = array();
  115. while($row = $this->fetch_assoc()) {
  116. $retval[] = $row;
  117. }
  118. return $retval;
  119. }
  120. }
  121.  
  122.  
  123. class DB_Mysql_Test extends DB_Mysql {
  124. protected $user  = DB_USER;
  125. protected $pass  = DB_PASS;
  126. protected $dbhost = DB_HOST;
  127. protected $dbname = DB_BAZA; 
  128.  
  129. public function __construct() { }
  130.  
  131. protected function connect()
  132. {
  133. $this->dbh = mysql_pconnect($this->dbhost, $this->user, $this->pass);
  134. if(!is_resource($this->dbh)) {
  135. throw new MysqlException;
  136. }
  137. if(!mysql_select_db($this->dbname, $this->dbh)) {
  138. throw new MysqlException;
  139. }
  140. $ret = mysql_query("SET CHARSET utf-8");
  141. if(!$ret) {
  142. 142 throw new MysqlException;
  143. }
  144. }
  145. } 
  146.  
  147. class DB_Mysql_Test_Debug extends DB_Mysql_Test {
  148. protected $elapsedTime;
  149. public function execute($query) {
  150. // set timer;
  151. parent::execute($query);
  152. // end timer;
  153. }
  154. public function getElapsedTime() {
  155. return $this->$elapsedTime;
  156. }
  157. }
  158.  
  159. class DB_Mysql_Prod extends DB_Mysql {
  160. protected $user  = "prod";
  161. protected $pass  = "secret";
  162. protected $dbhost = "dbhost";
  163. protected $dbname = "production";
  164.  
  165. public function __construct() { }
  166.  
  167. protected function connect()
  168. {
  169. $this->dbh = mysql_pconnect($this->dbhost, $this->user, $this->pass);
  170. if(!is_resource($this->dbh)) {
  171. throw new MysqlException;
  172. }
  173. if(!mysql_select_db($this->dbname, $this->dbh)) {
  174. throw new MysqlException;
  175. }
  176. $ret = mysql_query("SET CHARSET utf-8");
  177. if(!$ret) {
  178. throw new MysqlException;
  179. }
  180. }
  181. } 
  182. ?>
nospor
Cytat
Fatal error: Class 'MysqlException' not found
Jak glosi komunikat, nie znalazl klasy MysqlException.

Wszedzie z niej korzystasz: throw new MysqlException; ale nigdzie nie masz jej definicji, ot co

proszê poprawiæ tytu³ o znacznik zgodnie z zasadami forum Przedszkole:
Temat: Tematyka i zasady panujace na forum Przedszkole


Uzywaj wlasciwego bbcode exclamation.gif! - popraw swoj post
To jest wersja lo-fi g³ównej zawarto¶ci. Aby zobaczyæ pe³n± wersjê z wiêksz± zawarto¶ci±, obrazkami i formatowaniem proszê kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.