Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Zły kod błędu w SQLException na bazie MySQL, wszystko w Mojavi + Creole
mike
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 7 494
Pomógł: 302
Dołączył: 31.03.2004

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


Mam problem z pogranicza php i MySQL ale zdecydowałem się umieścić temat tutaj.

Zaczne od kodu:

AddQuestionAction.class.php
  1. <?php
  2.  
  3. // ...
  4.  
  5. public function execute()
  6. {
  7.  
  8. // Pobranie obiektów z kontekstu
  9. $objController = $this->getContext()->getController();
  10. $objRequest = $this->getContext()->getRequest();
  11. // ---
  12.  
  13. // Pobranie modeli
  14. $objModel = $objController->getModel( 'FAQ', 'AddQuestion' );
  15. // ---
  16.  
  17. try
  18. {
  19.  
  20. $objModel->addQuestion();
  21.  
  22. }
  23. catch( SQLException $objException )
  24. {
  25.  
  26. // Jakieś tam operacje
  27.  
  28.  
  29. return View::ERROR;
  30.  
  31. }
  32.  
  33. return View::SUCCESS;
  34.  
  35. }
  36.  
  37. // ...
  38.  
  39. ?>


AddQuestionModel.class.php
  1. <?php
  2.  
  3. // ...
  4.  
  5. public function addQuestion()
  6. {
  7.  
  8. // Pobranie modeli
  9. $objModel = $this->objController->getGlobalModel( 'FAQ' );
  10. // ---
  11.  
  12. // Pobranie parametrów żądania
  13. $strSectionName = $this->objRequest->getParameter( 'name' );
  14. $intLanguageId = $this->objRequest->getParameter( 'languageId' );
  15. $strQuestion = $this->objRequest->getParameter( 'question' );
  16. $strAnswer = $this->objRequest->getParameter( 'answer' );
  17. // ---
  18.  
  19. // Pobranie danych z modeli
  20. $intMaxCurrentPosition = $objModel->getLastPosition( $intLanguageId );
  21. // ---
  22.  
  23. $objStatment = $this->objConnection->prepareStatement( 'INSERT INTO faq SET languageId = ?, position = ?, question = ?, answer = ?' );
  24.  
  25. $arrParams = array(
  26.  $intLanguageId,
  27.  ( $intMaxCurrentPosition + 1 ),
  28.  $strQuestion,
  29.  $strAnswer
  30. );
  31. $intAffectedRows = $objStatment->executeUpdate( $arrParams );
  32.  
  33. if( $intAffectedRows > 0 )
  34. {
  35.  
  36. return true;
  37.  
  38. }
  39.  
  40. return false;
  41.  
  42. }
  43.  
  44. // ....
  45.  
  46. ?>


Jak widać powyżej - banalna operacja. W Akcji pobieram model i wykonuje jego metodę. Szafa gra, a przynajmniej powinna (IMG:http://forum.php.pl/style_emoticons/default/sad.gif)

Podam dodatkowo strukturę tabeli faq:
  1. CREATE TABLE `faq` (
  2. `id` int(10) NOT NULL AUTO_INCREMENT,
  3. `languageId` int(2) NOT NULL DEFAULT '0',
  4. `position` int(10) NOT NULL DEFAULT '1',
  5. `question` varchar(255) NOT NULL DEFAULT '',
  6. `answer` text NOT NULL,
  7. PRIMARY KEY (`id`),
  8. UNIQUE KEY `question` (`languageId`,`question`)
  9. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;


I teraz problem. Na pola languageId + question jest założony klucz unikalny. Co powinno zaowocowac wyrzuconym wyjątkiem podczas próby dodania tych samych danych.
I owszem wyjątek leci, ale ...
... z kodem błędu 0 (IMG:http://forum.php.pl/style_emoticons/default/exclamation.gif) !
A przecież zaburzenie unikalności klucza to kod błędu 1062 (jak się nie mylę).

Dlaczego tak się dzieje :?:

Dodatek:
MySQL 4.1.7
php 5.0.4
Abstrakt bazodanowy to Creole 1.0.9
Framework Mojavi 3.0.0 dev ( + moje zmiany ).
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 24.08.2025 - 16:21