Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP]Historia zmian
gogomania
post
Post #1





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 7.02.2013

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


Witam,
Mam zagwostkę, potrzebuję podpowiedzi jak zrobić pełną historię zmian do aplikacji webowej służącej do inwentaryzacji sprzętu.

Posiadam kilka tabel:
`wgd_uzytkownicy`:
  1. CREATE TABLE IF NOT EXISTS `wgd_uzytkownicy` (
  2. `uzytkownik_id` int(11) NOT NULL AUTO_INCREMENT,
  3. `login` varchar(32) NOT NULL COMMENT 'ad_samaccountname',
  4. `haslo` varchar(32) NOT NULL,
  5. `odzyskaj_haslo` int(11) NOT NULL DEFAULT '0',
  6. `imie` varchar(32) NOT NULL COMMENT 'ad_givenname',
  7. `nazwisko` varchar(32) NOT NULL COMMENT 'ad_sn',
  8. `firma_zatrudnienia` varchar(100) NOT NULL COMMENT 'ad_company',
  9. `dzial` varchar(45) NOT NULL COMMENT 'ad_department',
  10. `stanowisko` varchar(50) NOT NULL COMMENT 'ad_title',
  11. `adres_w_ad` varchar(200) NOT NULL COMMENT 'ad_streetaddress',
  12. `kod_pocztowy` varchar(10) NOT NULL COMMENT 'ad_postalcode',
  13. `miasto` varchar(50) NOT NULL COMMENT 'ad_l',
  14. `wojewodztwo` varchar(75) NOT NULL COMMENT 'ad_st',
  15. `email` varchar(1024) NOT NULL COMMENT 'ad_mail',
  16. `kod_email` varchar(32) NOT NULL,
  17. `allow_email` int(11) NOT NULL DEFAULT '1',
  18. `przekierowania_email_w_ad` varchar(200) NOT NULL COMMENT 'ad_proxyaddresses',
  19. `data_rejestracji` datetime NOT NULL,
  20. `data_utworzenia_konta_w_ad` varchar(150) NOT NULL COMMENT 'ad_whencreated',
  21. `data_zmiany_hasla_w_ad` varchar(150) NOT NULL COMMENT 'ad_pwdlastset',
  22. `data_ostatnio_zalogowany_w_ad` varchar(150) NOT NULL COMMENT 'ad_lastlogontimestamp',
  23. `status` int(11) NOT NULL DEFAULT '0',
  24. `typ` int(1) NOT NULL DEFAULT '0',
  25. `ip` varchar(15) NOT NULL,
  26. `profil` varchar(55) NOT NULL,
  27. `czas` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Czas aktualny',
  28. `guid` varchar(50) NOT NULL COMMENT 'ad_objectguid',
  29. `szerokosc` varchar(30) NOT NULL,
  30. `dlugosc` varchar(30) NOT NULL,
  31. `telefon_kom` varchar(12) NOT NULL COMMENT 'ad_mobile',
  32. `telefon_stac` varchar(20) NOT NULL COMMENT 'ad_telephonenumber',
  33. `telefon_voip` varchar(20) NOT NULL COMMENT 'ad_ipphone',
  34. `faks` varchar(25) NOT NULL COMMENT 'ad_facsimiletelephonenumber',
  35. `ile_logowan_w_ad` int(11) NOT NULL COMMENT 'ad_logoncount',
  36. `uwagi` varchar(450) NOT NULL COMMENT 'ad_info',
  37. `objectcategory` varchar(200) NOT NULL COMMENT 'ad_objectcategory',
  38. `objectclass` varchar(200) NOT NULL COMMENT 'ad_objectclass',
  39. `zalogowany` int(1) NOT NULL DEFAULT '0',
  40. PRIMARY KEY (`uzytkownik_id`)
  41. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;


`wgd_urz_komputery`:
  1. CREATE TABLE IF NOT EXISTS `wgd_urz_komputery` (
  2. `komputer_id` int(11) NOT NULL AUTO_INCREMENT,
  3. `uzytkownik_id` int(11) UNSIGNED NOT NULL COMMENT 'przygotowal sprzet `wgd_uzytkownicy`.`uzytkownik_id`',
  4. `producent_id` int(11) UNSIGNED NOT NULL,
  5. `model_id` int(11) UNSIGNED NOT NULL,
  6. `system_id` int(11) UNSIGNED NOT NULL,
  7. `firma_zat_id` int(11) UNSIGNED NOT NULL,
  8. `firma_id` int(11) UNSIGNED NOT NULL COMMENT 'firma zakupujaca',
  9. `dzial_id` int(11) UNSIGNED NOT NULL,
  10. `lokalizacja_id` int(11) UNSIGNED NOT NULL,
  11. `dostawca_id` int(11) NOT NULL,
  12. `nazwa` varchar(25) NOT NULL,
  13. `sn` varchar(20) NOT NULL,
  14. `pn` varchar(20) NOT NULL,
  15. `procesor` varchar(50) NOT NULL,
  16. `ram` varchar(10) NOT NULL,
  17. `gwarancja` varchar(25) NOT NULL,
  18. `klawiatura` int(1) UNSIGNED NOT NULL DEFAULT '0',
  19. `myszka` int(1) UNSIGNED NOT NULL DEFAULT '0',
  20. `sluchawki` int(1) UNSIGNED NOT NULL DEFAULT '0',
  21. `monitor` int(1) UNSIGNED NOT NULL DEFAULT '0',
  22. `klucz_vpn` int(1) UNSIGNED NOT NULL DEFAULT '0',
  23. `klucz_molp` int(1) UNSIGNED NOT NULL DEFAULT '0',
  24. `klucz_box` int(1) UNSIGNED NOT NULL DEFAULT '0',
  25. `outlook_2013` int(1) UNSIGNED NOT NULL DEFAULT '0',
  26. `exchange` int(1) UNSIGNED NOT NULL DEFAULT '0',
  27. `office_2010` int(1) UNSIGNED NOT NULL DEFAULT '0',
  28. `office_2013` int(1) UNSIGNED NOT NULL DEFAULT '0',
  29. `rdp` int(1) UNSIGNED NOT NULL DEFAULT '0',
  30. `status` int(1) NOT NULL DEFAULT '1',
  31. `data_dodania_urz` datetime NOT NULL,
  32. `data_zakupu` date NOT NULL,
  33. `data_wydania` date NOT NULL,
  34. `ostatnia_zmiana` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  35. `wlasciciel` varchar(70) NOT NULL COMMENT 'uzywany przez `wgd_uzytkownicy`.`uzytkownik_id`',
  36. `komentarz` varchar(300) NOT NULL,
  37. PRIMARY KEY (`komputer_id`)
  38. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=248 ;


`wgd_urz_telefony`:
  1. CREATE TABLE IF NOT EXISTS `wgd_urz_telefony` (
  2. `telefon_id` int(11) NOT NULL AUTO_INCREMENT,
  3. `uzytkownik_id` int(11) UNSIGNED NOT NULL COMMENT 'przygotowal sprzet `wgd_uzytkownicy`.`uzytkownik_id`',
  4. `producent_id` int(11) UNSIGNED NOT NULL,
  5. `model_id` int(11) UNSIGNED NOT NULL,
  6. `system_id` int(11) UNSIGNED NOT NULL,
  7. `firma_id` int(11) NOT NULL COMMENT 'Kupujacy sprzet',
  8. `dzial_id` int(11) UNSIGNED NOT NULL,
  9. `dostawca_id` int(11) NOT NULL,
  10. `sn` varchar(25) NOT NULL,
  11. `imei` varchar(20) NOT NULL,
  12. `gwarancja` varchar(25) NOT NULL,
  13. `data_dodania_urzadzenia` datetime NOT NULL,
  14. `data_zakupu` date NOT NULL,
  15. `data_wydania` date NOT NULL,
  16. `data_ostatnia_zmiana` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  17. `sluchawki` int(1) UNSIGNED NOT NULL DEFAULT '0',
  18. `ladowarka` int(1) UNSIGNED NOT NULL DEFAULT '0',
  19. `exchange` int(1) UNSIGNED NOT NULL DEFAULT '0',
  20. `status` int(1) UNSIGNED NOT NULL DEFAULT '1',
  21. `wlasciciel` varchar(70) NOT NULL COMMENT 'uzywany przez `wgd_uzytkownicy`.`uzytkownik_id`',
  22. `komentarz` varchar(1000) NOT NULL,
  23. PRIMARY KEY (`telefon_id`)
  24. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=223 ;


Czytałem wujka google ale wszystko co znajduje to historia dla samego MySQL... Ja potrzebuję PHP > MYSQL.
Czy ktoś może poradzić, ewentualnie wskazać działający kod php w postaci przyzkładu + struktura tabel?
Walczę z tym już kilka dni. Proszę o pomoc.
Go to the top of the page
+Quote Post
patry6123
post
Post #2





Grupa: Zarejestrowani
Postów: 72
Pomógł: 11
Dołączył: 4.12.2014

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


Co za problem? Robisz tabelę LOG o polach id, operacja, data, id_urzadzenia, osoba i ew. inne jak potrzebujesz i zawsze gdy wykonujesz operacje mysql_query musisz wykonać operację insert into LOG
Go to the top of the page
+Quote Post
gogomania
post
Post #3





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 7.02.2013

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


Twoja odpowiedź mnie nie przekonuje.
Możesz trochę rozwinąć?
Go to the top of the page
+Quote Post
com
post
Post #4





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


stwórz sobie po prostu zwykły trigger
Go to the top of the page
+Quote Post
gogomania
post
Post #5





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 7.02.2013

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


Poprawcie mnie jeżeli się mylę.
Mam utworzyć dodatkowe tabele dla:
`wgd_urz_komputery` tabelę `wgd_urz_komputery_historia`
`wgd_urz_telefony` tabelę `wgd_urz_komptery_historia`
i dopisać dla każdej z osobna trigger?
Czy zrobić to w jednej dużej tabeli, która posiada wszystkie pola z obu tabel?
Go to the top of the page
+Quote Post
com
post
Post #6





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


poco wszystkie pola, zapisuj tylko to co potrzebujesz do 1 tabeli a z której to ustalisz na bazie id które sobie ustalisz
Go to the top of the page
+Quote Post
gogomania
post
Post #7





Grupa: Zarejestrowani
Postów: 51
Pomógł: 1
Dołączył: 7.02.2013

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


Potrzebuję rejestrować wszystkie zmiany dokonane przez użytkownika.
Chcę wiedzieć, kto co zmienił i kiedy.
Nadal uzyskuje zdawkowe informacje. Czy ktoś może mi podać przykład takiej struktury tabeli dla podanych przeze mnie?
według mnie powinno wyglądać to tak (proszę o poprawienie mnie jeżeli się mylę):
`wgd_log`:
  1. CREATE TABLE IF NOT EXISTS `wgd_urz_komputery` (
  2. `log_id` int(11) NOT NULL AUTO_INCREMENT,
  3. `komputer_id` int(11) UNSIGNED NOT NULL,
  4. `telefon_id` int(11) UNSIGNED NOT NULL,
  5. `uzytkownik_id` int(11) UNSIGNED NOT NULL,
  6. `producent_id` int(11) UNSIGNED NOT NULL,
  7. `model_id` int(11) UNSIGNED NOT NULL,
  8. `system_id` int(11) UNSIGNED NOT NULL,
  9. `firma_id` int(11) UNSIGNED NOT NULL,
  10. `dzial_id` int(11) UNSIGNED NOT NULL,
  11. `lokalizacja_id` int(11) UNSIGNED NOT NULL,
  12. `dostawca_id` int(11) NOT NULL,
  13. `nazwa` varchar(25) NOT NULL,
  14. `sn` varchar(20) NOT NULL,
  15. `pn` varchar(20) NOT NULL,
  16. `imei` varchar(20) NOT NULL,
  17. `procesor` varchar(50) NOT NULL,
  18. `ram` varchar(10) NOT NULL,
  19. `gwarancja` varchar(25) NOT NULL,
  20. `klawiatura` int(1) UNSIGNED NOT NULL,
  21. `myszka` int(1) UNSIGNED NOT NULL,
  22. `sluchawki` int(1) UNSIGNED NOT NULL,
  23. `monitor` int(1) UNSIGNED NOT NULL,
  24. `klucz_vpn` int(1) UNSIGNED NOT NULL,
  25. `klucz_molp` int(1) UNSIGNED NOT NULL,
  26. `klucz_box` int(1) UNSIGNED NOT NULL,
  27. `outlook_2013` int(1) UNSIGNED NOT NULL,
  28. `exchange` int(1) UNSIGNED NOT NULL,
  29. `office_2010` int(1) UNSIGNED NOT NULL,
  30. `office_2013` int(1) UNSIGNED NOT NULL,
  31. `rdp` int(1) UNSIGNED NOT NULL,
  32. `status` int(1) NOT NULL,
  33. `data_dodania_urz` datetime NOT NULL,
  34. `data_zakupu` date NOT NULL,
  35. `data_wydania` date NOT NULL,
  36. `data_ostatnia_zmiana` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  37. `wlasciciel` varchar(70) NOT NULL,
  38. `komentarz` varchar(300) NOT NULL,
  39. `ladowarka` int(1) UNSIGNED NOT NULL,
  40. `exchange` int(1) UNSIGNED NOT NULL,
  41. PRIMARY KEY (`komputer_id`)
  42. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=248 ;

Go to the top of the page
+Quote Post
patry6123
post
Post #8





Grupa: Zarejestrowani
Postów: 72
Pomógł: 11
Dołączył: 4.12.2014

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


Ale po co trzymać dwa razy tą samą informację w bazie? W tabeli LOG trzymasz informacje o rodzaju zmiany i wartości jaką zmieniasz. Jak potrzebujesz pobrać informacje o zmianie to robisz select * form LOG INNER JOIN urzadzenie ON urzadzenie.id = log.id i zwraca Ci wszystko co chcesz
Go to the top of the page
+Quote Post
com
post
Post #9





Grupa: Zarejestrowani
Postów: 3 034
Pomógł: 366
Dołączył: 24.05.2012

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


dokładnie tak jak napisał patry6123, historia zmian to nie backup
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 Aktualny czas: 21.08.2025 - 21:52