![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 359 Pomógł: 12 Dołączył: 16.01.2009 Ostrzeżenie: (0%) ![]() ![]() |
W książce pt. "PHP5. Zaawansowanie programowanie" doszukałem się błędu. Mianowicie przy tworzeniu "Warstwy abstrakcji dla bazy danych" metoda Insert kończy się w taki sposób:
To chyba wiadome, że instrukcja Insert nie zwraca żadnej kotwicy do danych (w przeciwieństwie do funkcji Select). Testując kod zawsze rzuca mi on wyjątek o kodzie błędu 0 (czyli że go nie ma). Chciałbym się dowiedzieć, jak sprawdzać, czy zapytania Insert, Update i Delete się powiodły. Czy coś takiego będzie w porządku:
@EDIT: Już sprawdziłem, coś kurde nie działa, bo wywala mi taki błąd: Cytat Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in C:\Asmox\Programy\WebServ\httpd\KPiR\components\class.Database.php on line 58 Czyli jednak zwraca jakąś kotwicę. Wygląda na to, że to ja coś zwaliłem. Tylko co? Ten post edytował Asmox 19.06.2009, 14:12:33 -------------------- |
|
|
![]() |
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 4 340 Pomógł: 542 Dołączył: 15.01.2006 Skąd: Olsztyn/Warszawa Ostrzeżenie: (0%) ![]() ![]() |
Odpowiedz kryje się w manualu ( jak zawsze )
![]() http://pl.php.net/manual/en/function.mysql-affected-rows.php Cytat Parameters link_identifier The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated. http://pl.php.net/manual/en/function.mysql-query.php Cytat Return Values
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data. Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement. mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query. Ten post edytował skowron-line 19.06.2009, 14:52:53 -------------------- I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy. QueryBuilder, Mootools.net, bbcradio1::MistaJam http://www.phpbench.com/ |
|
|
![]()
Post
#3
|
|
![]() Grupa: Zarejestrowani Postów: 359 Pomógł: 12 Dołączył: 16.01.2009 Ostrzeżenie: (0%) ![]() ![]() |
to mam robić coś w tym stylu if(! mysql_query($sql)) throw new exception
-------------------- |
|
|
![]()
Post
#4
|
|
![]() Grupa: Zarejestrowani Postów: 4 340 Pomógł: 542 Dołączył: 15.01.2006 Skąd: Olsztyn/Warszawa Ostrzeżenie: (0%) ![]() ![]() |
to mam robić coś w tym stylu if(! mysql_query($sql)) throw new exception No raczej. -------------------- I'm so fast that last night I turned off the light switch in my hotel room and was in bed before the room was dark - Muhammad Ali.
Peg jeżeli chcesz uprawiać sex to dzieci muszą wyjść, a jeżeli chcesz żeby był dobry ty też musisz wyjść - Al Bundy. QueryBuilder, Mootools.net, bbcradio1::MistaJam http://www.phpbench.com/ |
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 24.07.2025 - 23:32 |