Připojení dibi k databazi
- Operanda
- Člen | 20
Jedu podle tutorialu QS TodoListu, ale nedari se mi pripojit k databazi.
Pokud zakomentuji dibi::connect; v bootstrapu, aplikace funguje (bez databaze
samozrejme), pokud tam tento radek necham, zobrazi se mi prazdna stranka
(500 internal err.) Aplikaci posilam rovnou na hosting a mam prefixovou verzi
nette 0.9.7
V bootstrapu.php mam:
<?php
/**
* My NApplication bootstrap file.
*
* @copyright Copyright (c) 2010 John Doe
* @package MyApplication
*/
// Step 1: Load Nette Framework
// this allows load Nette Framework classes automatically so that
// you don't have to litter your code with 'require' statements
require LIBS_DIR . '/Nette/loader.php';
// Step 2: Configure environment
// 2a) enable NDebug for better exception and error visualisation
NDebug::enable(NDebug::DETECT, APP_DIR . '/../log/error.log');
// 2b) load configuration from config.ini file
//NEnvironment::setName( 'production' ); //tímto musí být nastaven blok, který se načte z configu
NEnvironment::loadConfig();
// Step 3: Configure application
// 3a) get and setup a front controller
$application = NEnvironment::getApplication();
$application->errorPresenter = 'Error';
//$application->catchExceptions = TRUE;
// Step 4: Setup application router
$router = $application->getRouter();
$router[] = new NRoute('index.php', array(
'presenter' => 'Todolist',
'action' => 'show',
), NRoute::ONE_WAY);
$router[] = new NRoute('<presenter>/<action>/<id>', array(
'presenter' => 'Todolist',
'action' => 'show',
'id' => NULL,
));
dibi::connect((NEnvironment::getConfig('database'));
// Step 5: Run the application!
$application->run();
?>
A v config.ini:
;
; SECURITY WARNING: it is CRITICAL that this file & directory are NOT accessible directly via a web browser!
;
; If you don't protect this directory from direct web access, anybody will be able to see your passwords.
; https://nette.org/en/security-warning
;
[common]
; PHP configuration
php.date.timezone = "Europe/Prague"
php.iconv.internal_encoding = "UTF-8"
php.mbstring.internal_encoding = "UTF-8"
;php.default_charset = "UTF-8"
; variables
variable.lang = en
variable.tempDir = %appDir%/../temp
variable.logDir = %appDir%/../log
; services
service.Nette-Security-IAuthenticator = UsersModel
service.Nette-Loaders-RobotLoader.factory = Nette\NConfigurator::createRobotLoader
service.Nette-Loaders-RobotLoader.option.directory[] = %appDir%
service.Nette-Loaders-RobotLoader.option.directory[] = %libsDir%
service.Nette-Loaders-RobotLoader.run = TRUE
[production < common]
; common database connection
database.driver = mysql
database.database = jmeno databaze
database.charset = utf8
database.lazy = TRUE
database.host = localhost
database.username = jmeno
database.password = heslo
Diky za jakoukoliv radu, zkousel sem snad vsechno co se k tomu dalo vygooglit.
- h4kuna
- Backer | 740
Ahoj,
v první řade máš tam moc závorek
dibi::connect((NEnvironment::getConfig(„database“)); ta
tučná je navíc.
NEnvironment::getConfig(‚database‘) přetypuj na pole
(array)NEnvironment::getConfig(‚database‘);, pokud to nepřetypuješ nejsem
si jistej zda si s tím dibi poradí.
Pokud ti to háže error 500
- odkomentuj a nastav $application->catchExceptions = FALSE;
- ověř si že máš zapnutý development režim NEnvironment::isProduction() == FALSE;
EDIT:
jsem to psal nějak dlouho :D mezitím 3 odpovědi
Editoval matata (24. 1. 2011 16:41)
- Operanda
- Člen | 20
2 Padik:
Doplnil jsem to sem:
<?php
// Step 2: Configure environment
// 2a) enable NDebug for better exception and error visualisation
NDebug::enable(NDebug::DETECT, APP_DIR . '/../log/error.log');
NDebug::enable(NDebug::DEVELOPMENT);
?>
Jenze porad prazdna stranka a BugFix jen oznami 500 internal e.
Jo a v error.log nic neni.
- Stig
- Člen | 29
mam taky problem s dibi. Class ‚dibi‘ not found. Nechapu proč.. Mam 2.0 Alpha 2 php 5.2. s N.
bootstrap
<?php
require dirname(__FILE__) . '/../libs/Nette/loader.php';
NDebug::enable(NDebug::DEVELOPMENT);
NEnvironment::loadConfig();
$application = NEnvironment::getApplication();
$application->onStartup[] = create_function('', 'Sql::initialize();');
...
?>
a model sql
<?php
class Sql extends NObject
{
private $connection;
public static function initialize()
{
dibi::connect(NEnvironment::getConfig('database'));
}
public function __construct()
{
$this->connection = dibi::getConnection();
}
?>
struktura
/libs
--dibi
--Nette
dik za rady
Editoval Stig (25. 2. 2011 1:21)