Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][Zend_Db] Polaczenie z mysql i obsluga
aggreSSive115
post 14.09.2011, 11:49:20
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 11.09.2011

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


Witam,

mam problem ze "zrozumieniem" tutoriala na stronie zenda, wiec postanowilem tutaj napisac o pomoc smile.gif Chcialbym polaczyc sie z baza danych uzywajac Zend_Db, jednak mam problem z samym ustaleniem polaczenia. W pliku application.ini mam wpisane:

Kod
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

resources.db.adapter = pdo_mysql
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = testnews
resources.db.params.charset = utf8
resources.db.isDefaultTableAdapter = true

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1


I teraz chcialbym sie zapytac jak zrobic, aby te ustawienia wywolac, lub zeby polaczenie z baza danych bylo automatyczne?

Pozdrawiam!
Go to the top of the page
+Quote Post
cezarszl
post 14.09.2011, 14:19:07
Post #2





Grupa: Zarejestrowani
Postów: 36
Pomógł: 1
Dołączył: 18.11.2009
Skąd: Cz-wa

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


Na przykład tworzysz model dla wybranej tabeli przy pomocy Zend_Tools, badź ręcznie w katalogu models/DbTable.

  1. <?php
  2.  
  3. class Application_Model_DbTable_Table extends Zend_Db_Table_Abstract
  4. {
  5.  
  6. protected $_name = 'table';
  7.  
  8. }


A potem np. w controllerze, gdzie potrzebujesz jakieś dane z tej tabeli:

  1.  
  2. <?php
  3.  
  4. class HomeController extends Zend_Controller_Action
  5. {
  6.  
  7. public function init()
  8. {
  9. /* Initialize action controller here */
  10. }
  11.  
  12. public function indexAction()
  13. {
  14. $table = new Application_Model_DbTable_Table;
  15. $result = $table->fetchAll();
  16. $resultArray = $result->toArray();


w wyniku tego otrzymujesz wszystkie rekordy z tabeli 'table' w tablicy $resultArray.


--------------------
ja być noob
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 - 09:59