login  Naam:   Wachtwoord: 
Registreer je!
 Forum

error in class

Offline bertlim - 16/03/2006 18:12
Avatar van bertlimPHP interesse Hoi iedereen,

ik ben pas begonnen met classes en ik heb nu een mysqlclass gemaakt.
Maar nu krijg ik deze error:

Fatal error: Cannot redeclare class mysqldatabase in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 11

dit is men code:

  1. <?php
  2. class MySqlDatabase
  3. {
  4.  
  5. var $host = '';
  6. var $user = '';
  7. var $pass = '';
  8. var $data = '';
  9. var $connected = false;
  10. var $connectie;
  11. var $countquerys = 0;
  12. var $querytime;
  13. var $execed;
  14.  
  15. function cError($title,$error)
  16. {
  17. echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
  18. echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
  19. }
  20.  
  21. function cConnect($host, $user, $pass, $data)
  22. {
  23. if($this->connected = false)
  24. {
  25. $this->connectie = mysql_connect($host,$user,$pass);
  26. }
  27. elseif($this->connected = true && isset($this->connectie))
  28. {
  29. return $this->connectie;
  30. }
  31. elseif(!mysql_connect($data))
  32. {
  33. die($this->cError('Database Error ::','The database can not be found. Try again later.'));
  34. }
  35. else
  36. {
  37. $this->connected = true;
  38. }
  39. }
  40.  
  41. function cMicrotime()
  42. {
  43. $time = explode(' ', microtime());
  44. return $time[0] + $time[1];
  45. }
  46.  
  47. function cQuerys($input)
  48. {
  49. $start_time = $this->cMicrotime();
  50. $query = mysql_query($input) or die($this->error('Query Error ::', 'An error occured while processing the query.'));
  51. $this->execed = 1;
  52. $this->countquerys++;
  53.  
  54. $time = $this->cMicrotime() - $start_time;
  55. $this->querytime += $time;
  56.  
  57. return $query;
  58. }
  59.  
  60. function cFetch($input)
  61. {
  62. if($this->execed != 1)
  63. {
  64. die($this->cError('Query Error ::', 'No query processed.'));
  65. }
  66. return mysql_fetch_assoc($input);
  67. }
  68.  
  69. function cNumRows($input)
  70. {
  71. if($this->execed != 1)
  72. {
  73. die($this->cError('Query Error ::', 'No query processed.'));
  74. }
  75. return mysql_num_rows($input);
  76. }
  77.  
  78. function cQueryOutput()
  79. {
  80. if($this->countquerys == 1)
  81. {
  82. echo '<font face="verdana" size="8">1 query executed.</font>';
  83. $query_name = 'query';
  84. }
  85. else
  86. {
  87. echo '<font face="verdana" size="8"> '.$this->countquerys.' query\'s executed.</font>';
  88. $query_name = 'query\'s';
  89. }
  90. echo '<br><font face="verdana" size="8">'.$query_name.' executed in '.round($this->querytime,5).' Ms.</font>';
  91. }
  92.  
  93. }
  94.  
  95.  
  96. ?>

Kan iemand me helpen?

bedankt bij voorbaat,

Bertlim

9 antwoorden

Gesponsorde links
Offline vinTage - 16/03/2006 18:47 (laatste wijziging 16/03/2006 18:47)
Avatar van vinTage Nieuw lid Fatal error: Cannot redeclare class mysqldatabase in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 11

Je kan class maar één keer aanroepen, dus wss roep je elders die class nog eens aan (in een include mss? )
Offline bertlim - 16/03/2006 20:58 (laatste wijziging 16/03/2006 21:02)
Avatar van bertlim PHP interesse ok dit probleem is nu opgelost maar nu krijg ik deze errors:

Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 39

Warning: mysql_select_db(): A link to the server could not be established in /www/users/bertlim.downfire.com/classes/SQLclass.php on line 39

Code:
  1. <?php
  2. class MySqlDatabase
  3. {
  4.  
  5. var $host = '';
  6. var $user = '';
  7. var $pass = '';
  8. var $data = '';
  9. var $connected = false;
  10. var $connectie;
  11. var $countquerys = 0;
  12. var $querytime;
  13. var $execed;
  14.  
  15. function cError($title,$error)
  16. {
  17. echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
  18. echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
  19. }
  20.  
  21. function cConnect($host, $user, $pass, $data)
  22. {
  23. if($this->connected = false)
  24. {
  25. $this->connectie = mysql_connect($host,$user,$pass);
  26. }
  27. elseif($this->connected = true && isset($this->connectie))
  28. {
  29. return $this->connectie;
  30. }
  31. elseif(!mysql_select_db($data))
  32. {
  33. die($this->cError('Database Error ::','The database can not be found. Try again later.'));
  34. }
  35. else
  36. {
  37. $this->connected = true;
  38. }
  39. }
  40.  
  41. function cMicrotime()
  42. {
  43. $time = explode(' ', microtime());
  44. return $time[0] + $time[1];
  45. }
  46.  
  47. function cQuerys($input)
  48. {
  49. $start_time = $this->cMicrotime();
  50. $query = mysql_query($input) or die($this->error('Query Error ::', 'An error occured while processing the query.'));
  51. $this->execed = 1;
  52. $this->countquerys++;
  53.  
  54. $time = $this->cMicrotime() - $start_time;
  55. $this->querytime += $time;
  56.  
  57. return $query;
  58. }
  59.  
  60. function cFetch($input)
  61. {
  62. if($this->execed != 1)
  63. {
  64. die($this->cError('Query Error ::', 'No query processed.'));
  65. }
  66. return mysql_fetch_assoc($input);
  67. }
  68.  
  69. function cNumRows($input)
  70. {
  71. if($this->execed != 1)
  72. {
  73. die($this->cError('Query Error ::', 'No query processed.'));
  74. }
  75. return mysql_num_rows($input);
  76. }
  77.  
  78. function cQueryOutput()
  79. {
  80. if($this->countquerys == 1)
  81. {
  82. echo '<font face="verdana" size="8">1 query executed.</font>';
  83. $query_name = 'query';
  84. }
  85. else
  86. {
  87. echo '<font face="verdana" size="8"> '.$this->countquerys.' query\'s executed.</font>';
  88. $query_name = 'query\'s';
  89. }
  90. echo '<br><font face="verdana" size="8">'.$query_name.' executed in '.round($this->querytime,5).' Ms.</font>';
  91. }
  92.  
  93. }
  94.  
  95.  
  96. ?>

kan iemand me helpen?

Bedankt bij voorbaat,

Bertlim
Offline ikkedikke - 17/03/2006 16:30
Avatar van ikkedikke PHP expert heb je voor host wel iets ingevuld? zo nee: dan moet je bij je host te raden gaan, zo ja: wat dan?
Offline MothZone - 17/03/2006 16:34
Avatar van MothZone PHP ver gevorderde Regels (volgens script hierboven) 23 tot 27:
  1. if($this->connected = false)
  2. {
  3. $this->connectie = mysql_connect($host,$user,$pass);
  4. }
  5. elseif($this->connected = true && isset($this->connectie))

Moet dit zijn:
  1. if($this->connected == false)
  2. {
  3. $this->connectie = mysql_connect($host,$user,$pass);
  4. }
  5. elseif($this->connected == true && isset($this->connectie))


Als je if($a = $b) doet, dan krijgt $a de waarde van $b, en geeft hij automatisch true, als je if($a == $b) doet, geeft hij alleen true als ze aan elkaar gelijk zijn.
Offline Stijn - 17/03/2006 16:34 (laatste wijziging 17/03/2006 16:35)
Avatar van Stijn PHP expert if($this->connected = false) //in je connect function

oMg, zo staan d'er nog los eerst die op en test nog eens. Denk ook eens logisch na bij iedere lijn dat je script en script niet zomaar overtollige bytes 

edit

idem MothZone 
Offline bertlim - 17/03/2006 17:10
Avatar van bertlim PHP interesse ok hij werkt nu.

bedankt allemaal!
Offline timo - 17/03/2006 17:14
Avatar van timo PHP ver gevorderde als je false of true wil weten is het === d8 k..
Offline Stijn - 17/03/2006 18:00
Avatar van Stijn PHP expert === is om te kijken of hij gelijk is en zelfde type heeft
dus if($var === true){ blaat();
$var moet true zijn en een bool zijn

(randinfo )
Offline bertlim - 17/03/2006 22:43
Avatar van bertlim PHP interesse nu heb ik een ander probleem met een andere class.
Ik krijg bij het inloggen mooi het inlog venstertje te zien en als ik inlog krijg ik deze error:

Fatal error: Call to a member function on a non-object in /www/users/bertlim.downfire.com/classes/Memberclass.php on line 137

dit is men code:
  1. <?
  2. class MemberClass
  3. {
  4.  
  5. function cError($title,$error)
  6. {
  7. echo '<font face="verdana" size="12" color="#FF0033"> '.$title.' </font><p>';
  8. echo '<font face="Verdana" size="10" color="#FF0000"> '.$error.' </font>';
  9. }
  10.  
  11. function cSuperAdmin()
  12. {
  13. if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
  14. {
  15. $MyQu[0] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
  16. if($db->cNumRows($MyQu[0]) != 1)
  17. {
  18. die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
  19. }
  20. $MyAs[0] = $db->cFetch($MyQu[0]);
  21. if($_SESSION['user'] == $MyAs[0]['username'] && $_SESSION['pass'] == $MyAs[0]['pass'] && $MyAs[0]['level'] == '4')
  22. {
  23. return true;
  24. }
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30. }
  31.  
  32. function cAdmin()
  33. {
  34. if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
  35. {
  36. $MyQu[1] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
  37. if($db->cNumRows($MyQu[1]) != 1)
  38. {
  39. die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
  40. }
  41. $MyAs[1] = $db->cFetch($MyQu[1]);
  42. if($_SESSION['user'] == $MyAs[1]['username'] && $_SESSION['pass'] == $MyAs[1]['pass'] && $MyAs[1]['level'] == '3')
  43. {
  44. return true;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51. }
  52.  
  53. function cModerator()
  54. {
  55. if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
  56. {
  57. $MyQu[2] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
  58. if($db->cNumRows($MyQu[2]) != 1)
  59. {
  60. die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
  61. }
  62. $MyAs[2] = $db->cFetch($MyQu[2]);
  63. if($_SESSION['user'] == $MyAs[2]['username'] && $_SESSION['pass'] == $MyAs[2]['pass'] && $MyAs[2]['level'] == '2')
  64. {
  65. return true;
  66. }
  67. else
  68. {
  69. return false;
  70. }
  71. }
  72. }
  73.  
  74. function cMember()
  75. {
  76. if(!empty($_SESSION['user']) && !empty($_SESSION['pass']))
  77. {
  78. $MyQu[3] = $db->cQuerys("SELECT * FROM members WHERE username = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."'");
  79. if($db->cNumRows($MyQu[3]) != 1)
  80. {
  81. die($this->cErrors('User Error ::','The user can not be found, or your login data is wrong.'));
  82. }
  83. $MyAs[3] = $db->cFetch($MyQu[3]);
  84. if($_SESSION['user'] == $MyAs[3]['username'] && $_SESSION['pass'] == $MyAs[3]['pass'] && $MyAs[3]['level'] == '1')
  85. {
  86. return true;
  87. }
  88. else
  89. {
  90. return false;
  91. }
  92. }
  93. }
  94.  
  95. function cRegister($username,$pass,$pass_confirm,$email)
  96. {
  97. if(!empty($username) && !empty($pass) && !empty($pass_confirm)&& !empty($email))
  98. {
  99. if($pass == $pass_confirm)
  100. {
  101. $MyQu[4] = $db->cQuerys("SELECT * FROM members WHERE username = '".$username."'");
  102. $MyNu[0] = $db->cNumRows($MyQu[4]);
  103. if($MyNu[0] != 1)
  104. {
  105. $db->cQuerys("INSERT INTO members username, pass, email, level VALUES ('".$username."','".$pass."','".$email."','1')");
  106. echo 'Registration Complete.<a href="login.php">login</a>.';
  107. }
  108. else
  109. {
  110. $this->cErrors('User Error ::','The username already exists.Choose another one.');
  111. }
  112. }
  113. else
  114. {
  115. $this->cErrors('Password Error ::','Your passwords do not match.');
  116. }
  117. }
  118. else
  119. {
  120. $this->cErrors('Input Error ::','You need to fill in all fields.');
  121. }
  122. }
  123.  
  124. function cLogin($username,$pass)
  125. {
  126. if(!empty($username) && !empty($pass))
  127. {
  128. $MyQu[5] = $db->cQuerys("SELECT * FROM members WHERE username = '".$username."' AND pass = '".$pass."'");
  129. $MyNu[1] = $db->cNumRows($MyQu[5]);
  130. if($MyNu[1] != 0)
  131. {
  132. $_SESSION['user'] = $user;
  133. $_SESSION['pass'] = $pass;
  134.  
  135. echo 'Login Succesfull. <a href="index.php">Go to index</a>.';
  136. }
  137. else
  138. {
  139. $this->cErrors('User Error ::','This User does not exist or your login data is wrong.');
  140. }
  141. }
  142. else
  143. {
  144. $this->cErrors('Input Error ::','You need to fill in all fields.');
  145. }
  146. }
  147.  
  148. function MembersList()
  149. {
  150. $MyQu[6] = $db->cQuerys("SELECT * FROM members ORDER BY id DESC");
  151. $MyNu[2] = $db->cNumRows($MyQu[6]);
  152.  
  153. if($MyNu[2] == 0)
  154. {
  155. echo 'No members registered yet.';
  156. }
  157.  
  158. while($MyAs[4] = $db->cFetch($MyQu[6]))
  159. {
  160. echo '<table>
  161. <tr>
  162. <td width="200">Name</td>
  163. <td width="200">Email</td>
  164. <td width="200">Status</td>
  165. </tr>
  166. <tr>
  167. <td width="200">'.$MyAs[4]['username'].'</td>
  168. <td width="200">'.$MyAs[4]['email'].'</td>
  169. <td width="200">'.$status.'</td>';
  170. }
  171. }
  172.  
  173. }
  174.  
  175. ?>


kan iemand me helpen?

bedankt bij voorbaat,

Bertlim
Gesponsorde links
Dit onderwerp is gesloten.
Actieve forumberichten
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.391s