Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z klasą mysql, Porszę o pomoc!
virtualman
post 9.10.2011, 20:01:24
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 0
Dołączył: 17.03.2011

Ostrzeżenie: (0%)
-----


Witam zacząłem pisać własną klase, ale mam błędy:
  1. ! ) Warning: mysql_query() expects parameter 2 to be resource, null given in C:\wamp\www\gra\class.php on line 47
  2. Call Stack
  3. # Time Memory Function Location
  4. 1 0.0006 670512 {main}( ) ..\index.php:0
  5. 2 0.0052 725288 user->add( ) ..\index.php:6
  6. 3 0.0054 726152 mysql->query( ) ..\class.php:97
  7. 4 0.0054 726200 mysql_query ( ) ..\class.php:47
  8.  
  9.  
  10. ( ! ) Warning: mysql_close() expects parameter 1 to be resource, null given in C:\wamp\www\gra\class.php on line 62
  11. Call Stack
  12. # Time Memory Function Location
  13. 1 0.0057 716504 mysql->__destruct( ) ..\class.php:0
  14. 2 0.0057 716552 mysql_close ( ) ..\cl

Kod PHP to:
  1. class mysql
  2. {
  3. private $host='localhost';
  4. private $name='root';
  5. private $pas='';
  6. private $db='game';
  7. private $handler;
  8.  
  9. public function connect(){
  10. $this->handler=mysql_connect($this->host,$this->name,$this->pas)
  11. or die('Błąd podczas łączenia z bazą danych.');
  12. mysql_select_db($this->db,$this->handler)
  13. or die('Błąd podczas łączenia z bazą danych.');
  14. }
  15.  
  16. public function set($host,$name,$pas,$db){
  17. $this->host = $host;
  18. $this->name = $name;
  19. $this->pas = $pas;
  20. $this->db = $db;
  21. }
  22.  
  23. public function query($query){
  24. $return=mysql_query($query,$this->handler);
  25. return $return;
  26. }
  27.  
  28. public function query_num($query){
  29. $result = mysq_query($query,$this->handler);
  30. return mysql_num_rows($result);
  31. }
  32.  
  33. public function query_fetch($query){
  34. $result = mysql_query($query,$this->handler);
  35. return mysql_fetch_array($result);
  36. }
  37.  
  38. public function __destruct(){
  39. mysql_close($this->handler);
  40. }
  41. }
  42.  
  43. class user extends mysql
  44. {
  45.  
  46. private $id;
  47.  
  48. public function setid($id){
  49. $this->id=$id;
  50. }
  51.  
  52. public function getid(){
  53. return $this->id;
  54. }
  55.  
  56. public function add($username,$password,$mail){
  57. $time=time();
  58. $data=date("d.m.Y");
  59. $code="";
  60. for($l=1; $l<=24; $l++){
  61. $a=rand(0,2);
  62. switch($a){
  63. case 0:
  64. $code .= chr(rand(30,39));
  65. break;
  66. case 1:
  67. $code .= chr(rand(65,90));
  68. break;
  69. case 2:
  70. $code .= chr(rand(97,122));
  71. break;
  72. }
  73. }
  74. $this->query("INSERT INTO user ('user','password','mail','date','last','activate') VALUES ('$username','$password','$mail','$data','$time',$code)");
  75. }
  76. }

Proszę o pomoc!
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 19.07.2025 - 18:35