Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MYSQL]Co jest lepsze, REPLACE vs UPDATE i INSERT
Czapla
post 2.07.2008, 12:23:28
Post #1





Grupa: Zarejestrowani
Postów: 130
Pomógł: 3
Dołączył: 10.12.2007
Skąd: Bielsko-Biała

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


Co jest lepsze dla bazy danych, chodzi mi o wydajność.

  1. <?php
  2. if (isset ($ID_TEST) && $ID_TEST > 0)
  3.  {
  4.  $SQL = "UPDATE tabela_test SET test='"; 
  5.  $SQL .= $test;
  6.  $SQL .= "', test2='";
  7.  $SQL .= $test2;
  8.  $SQL .= "', test3='";
  9.  $SQL .= $test3;
  10.  $SQL .= " where id_test=".$id_test;
  11.  
  12. //(...)
  13.  }
  14. else
  15.  {
  16.  $SQL = "INSERT INTO tabela_test (test, test2, test3) VALUES('";
  17.  $SQL .= $test;
  18.  $SQL .= "','";
  19.  $SQL .= $test2;
  20.  $SQL .= "','";
  21.  $SQL .= $test3;
  22.  $SQL .= "'";
  23.  $SQL .= ")";
  24. //(..)
  25.  
  26. }
  27. ?>


czy może

  1. <?php
  2. $SQL = "REPLACE INTO tabela_test (test, test2, test3) VALUES ('";
  3.  $SQL .= $test;
  4.  $SQL .= "','";
  5.  $SQL .= $test2;
  6.  $SQL .= "','";
  7.  $SQL .= $test3;
  8.  $SQL .= "'";
  9.  $SQL .= ")";
  10.  
  11. //(...)
  12. ?>

?

Pozdrawiam

Ten post edytował Czapla 2.07.2008, 12:35:26


--------------------
Life is a game, continue playing and try to be a pr0.
Go to the top of the page
+Quote Post
Cysiaczek
post 2.07.2008, 12:26:19
Post #2





Grupa: Moderatorzy
Postów: 4 465
Pomógł: 137
Dołączył: 26.03.2004
Skąd: Gorzów Wlkp.




W tym przypadku to drugie smile.gif

Pozdrawiam.

p.s - dodaj tag do tematu


--------------------
To think for yourself you must question authority and
learn how to put yourself in a state of vulnerable, open-mindedness;
chaotic, confused, vulnerability, to inform yourself.
Think for yourself. Question authority.
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: 14.08.2025 - 00:18