Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sterownik MySQL nie wykonuje INSERT i UPDATE
batat
post 15.03.2008, 17:08:35
Post #1





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 8.03.2004
Skąd: Stalowa Wola

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


Witam,
Uzywam na swojej stronie ponizszego sterownika MySQL:

  1. <?php
  2. if(phpversion()<'5.0.0') {
  3. function file_put_contents($plik, $dane) {
  4. $f = fopen($plik, 'w');
  5. fwrite($f, $dane);
  6. fclose($f);
  7. }
  8. }
  9.  
  10. define('CACHE_DIR', './cache/');
  11.  
  12. class sql {
  13. var $connection;
  14. var $result;
  15. var $rows;
  16. var $queries = 0;
  17.  
  18. var $cache_mode; # 0 - disabled; 1 - enabled; 2 - enabled with generating cache file
  19. var $cache_buffer;
  20. var $cache_file;
  21. var $cache_ptr;
  22.  
  23.  
  24. function connect($host, $user, $pass, $db) {
  25. $this->connection = mysql_connect($host, $user, $pass);
  26. $this->query("SET NAMES 'utf8'");
  27. }
  28.  
  29. function __destruct() {
  30. if(is_resource($this->connection))
  31. mysql_close($this->connection);
  32. }
  33.  
  34. function cache_remove($handle) {
  35. if(file_exists(CACHE_DIR.'%%_'.$handle.'.cch'))
  36. unlink(CACHE_DIR.'%%_'.$handle.'.cch');
  37. }
  38.  
  39. function cache($handle = 0) {
  40. if(is_string($handle)) {
  41. if(file_exists(CACHE_DIR.'%%_'.$handle.'.cch')) {
  42. $this -> cache_mode = 1;
  43. $this -> cache_ptr = 0;
  44. $this -> cache_buffer = unserialize(file_get_contents(CACHE_DIR.'%%_'.$handle.'.cch'));
  45. }
  46. else {
  47. $this -> cache_mode = 2;
  48. $this -> cache_buffer = array();
  49. $this -> cache_file = CACHE_DIR.'%%_'.$handle.'.cch';
  50. }
  51. } else {
  52. if($this->cache_mode == 2) {
  53. file_put_contents($this->cache_file, serialize($this->cache_buffer));
  54. }
  55. $this->cache_mode = 0;
  56. }
  57. }
  58.  
  59. function num_rows() {
  60. if($this->cache_mode == 1)
  61. return count($this->cache_buffer);
  62. else
  63. return mysql_num_rows($this->result);
  64. }
  65.  
  66. function query($query) {
  67. if($this->cache_mode != 1) {
  68. $this->result = mysql_query($query) or die(mysql_error());
  69. $this->queries++;
  70. }
  71. }
  72.  
  73. function sql_result() {
  74. if($this->cache_mode == 1)
  75. return count($this->cache_buffer);
  76. else
  77. return mysql_result($this->result, 0);
  78. }
  79.  
  80. function fetch_array() {
  81. if($this->cache_mode == 1) {
  82. if(!isset($this->cache_buffer[$this->cache_ptr])) {
  83. return false;
  84. }
  85. $this->rows = $this->cache_buffer[$this->cache_ptr];
  86. $this->cache_ptr++;
  87. return true;
  88. } else {
  89. if($this->rows = mysql_fetch_assoc($this->result)) {
  90. if($this->cache_mode == 2) {
  91. $this->cache_buffer[] = $this->rows;
  92. }
  93. return true;
  94. }
  95. }
  96. return false;
  97. }
  98.  
  99. function close(){
  100.  mysql_close($this -> connection);
  101.  $dir = @opendir(CACHE_DIR);
  102.  $time = time() - 4*60;
  103. while($plik = @readdir($dir)){
  104. if($plik != '.' && $plik != '..' && $plik != ".htaccess" && @filemtime(CACHE_DIR.''.$plik) < $time){
  105. @unlink(CACHE_DIR.''.$plik);
  106. }
  107. }  
  108. }
  109.  
  110.  
  111. }
  112. ?>


jakis czas temu wszystko jeszcze dzialalo. Nagle mu sie cos odwidzialo i nie wykonuje mi niektorych zapytan sql. Np takiego:

  1. <?php
  2. $sql->query("INSERT INTO f_ulubione SET id_id = '".$_GET['id']."', user = '".$_SESSION['uid']."', dodane = '".time()."'");
  3. ?>


zapytania sa dobre, bo tak jak pisalem juz, wczesniej dzialaly. Teraz je dodatowo wyswietlalem i recznie wklepywalem do phpmyadmina i wszystko smiga.

Druga sprawa to, ze np. instrukcj $sql->num_rows(); zwraca mi wartosc 1, gdzie normalnie powinna zwrocic wartosc 0 :/ Troche mnie ta sytuacja irytuje, bo nie wiem co moze byc zle i gdzie mam szukac przyczyn bledu. Zaznaczam ze sterownik nie jest mojego autorstwa.

Ten post edytował batat 15.03.2008, 17:11:42
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 6)
Cezar708
post 15.03.2008, 19:41:02
Post #2





Grupa: Zarejestrowani
Postów: 1 116
Pomógł: 119
Dołączył: 10.05.2005
Skąd: Poznań

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


  1. INSERT INTO f_ulubione SET id_id = '".$_GET['id']."', user = '".$_SESSION['uid']."', dodane = '".time()."'


to nie jest poprawne zapytanie SQL

jak jest INSERT to nie ma SET, SET jest przy UPDATE.

Pozdrawiam
Go to the top of the page
+Quote Post
batat
post 16.03.2008, 00:21:08
Post #3





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 8.03.2004
Skąd: Stalowa Wola

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


jakby bylo niepoprawne to by mysql nie przepuszczal przez phpmy czy tez zwykle mysql_query() smile.gif

w takim razie jak jest poprawnie wg Ciebie? ;-)
Go to the top of the page
+Quote Post
cinekz
post 16.03.2008, 11:37:20
Post #4





Grupa: Zarejestrowani
Postów: 50
Pomógł: 6
Dołączył: 15.06.2006

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


@Cezar708: To jest poprawne zapytanie MySQL: http://dev.mysql.com/doc/refman/5.1/en/insert.html (patrz drugi sposób)
Go to the top of the page
+Quote Post
batat
post 16.03.2008, 20:31:56
Post #5





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 8.03.2004
Skąd: Stalowa Wola

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


nie ma nikt innych sugestii odnosnie tego dziwnego zachowania sterownika? ;-)
Go to the top of the page
+Quote Post
Xniver
post 16.03.2008, 23:10:20
Post #6





Grupa: Zarejestrowani
Postów: 108
Pomógł: 26
Dołączył: 29.02.2008

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


Może po prostu zaktualizowali wersje MySQLa. Czy na prawdę tak trudno zmienić zapytanie?
Go to the top of the page
+Quote Post
batat
post 19.03.2008, 16:43:51
Post #7





Grupa: Zarejestrowani
Postów: 94
Pomógł: 0
Dołączył: 8.03.2004
Skąd: Stalowa Wola

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


MySql nie byl aktualizowany bo pytalem. Zmiana zapytania tez nie pomogla...
Go to the top of the page
+Quote Post

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: 24.07.2025 - 16:07