Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP]Aplikacja w php i baza danych. CDbException
Forum PHP.pl > Forum > Przedszkole
btx270
Witam, na początku od razu uczciwie przyznam, że to mój totalnie pierwszy kontakt z php. Generalnie przyszło mi uruchomić na serwerze lokalnym aplikacje napisaną w php, aplikacja ta ma się otwierać przez przeglądarkę tylko wyłącznie na lokalnym adresie, nie ma wychodzić w świat smile.gif Tak więc po wstępnej konfiguracji środowiska i wgraniu w odpowiednie foldery aplikacji, bazy danych, chciałem sprawdzić czy to w ogóle ruszy, no i napotkałem na taki problem, po wpisaniu adresu localhost/aplikacja do przeglądarki wyskoczył komunikat: CDbException

CDbConnection failed to open the DB connection i nic więcej, próbowałem jeszcze w index.php wywołać bezpośrednie połączenie z tą bazą żeby mieć pewność z czym to się łączy i generalnie za każdym razem ta sama sytuacja

skrypt do bezpośredniego połaczenia:
<?php
/******************************************************
* connection.php
* konfiguracja połączenia z bazą danych
******************************************************/

function connection() {
// serwer
$mysql_server = "localhost";
// admin
$mysql_admin = "user";
// hasło
$mysql_pass = "password";
// nazwa baza
$mysql_db = "baza";
// nawiązujemy połączenie z serwerem MySQL
@mysql_connect($mysql_server, $mysql_admin, $mysql_pass)
or die('Brak połączenia z serwerem MySQL.');
// łączymy się z bazą danych
@mysql_select_db($mysql_db)
or die('Błąd wyboru bazy danych.');
}

?>


Star
znaczek "@" powoduje ,że nie widzisz konkretnych błędów, polecam go usunąć.

Jaki masz system i w jaki sposob zainstalowales swoje srodowisko do programowania ? Zainstalowales mysql'a ?
btx270
Zainstalowałem wampserver, w nim : wchodzi m.in. serwer HTTP Apache (2.2.22), serwer baz danych MySQL (5.6.12), interpreter PHP (5.4.16), narzędzie do zarządzania bazami danych phpMyAdmin (4.0.4), debugger i profiler XDebug (2.2.3), a także SQLBuddy (1.3.3), haha.gifC (1.5) oraz webGrind (1.0)
Z czego korzystam tylko z 4 pierwszych. Wcześniej miałem takie błędy:

CDbException

C:\wamp\www\app\protected\vendors\Yii\db\CDbConnection.php(382)

370 throw new CDbException('CDbConnection.connectionString cannot be empty.');
371 try
372 {
373 Yii::trace('Opening DB connection','system.db.CDbConnection');
374 $this->_pdo=$this->createPdoInstance();
375 $this->initConnection($this->_pdo);
376 $this->_active=true;
377 }
378 catch(PDOException $e)
379 {
380 if(YII_DEBUG)
381 {
382 throw new CDbException('CDbConnection failed to open the DB connection: '.
383 $e->getMessage(),(int)$e->getCode(),$e->errorInfo);
384 }
385 else
386 {
387 Yii::log($e->getMessage(),CLogger::LEVEL_ERROR,'exception.CDbException');
388 throw new CDbException('CDbConnection failed to open the DB connection.',(int)$e->getCode(),$e->errorInfo);
389 }
390 }
391 }
392 }
393
394 /**

Stack Trace
#0

C:\wamp\www\app\protected\vendors\Yii\db\CDbConnection.php(330): CDbConnection->open()

325 public function setActive($value)
326 {
327 if($value!=$this->_active)
328 {
329 if($value)
330 $this->open();
331 else
332 $this->close();
333 }
334 }
335

#1

C:\wamp\www\app\protected\vendors\Yii\db\CDbConnection.php(308): CDbConnection->setActive(true)

303 */
304 public function init()
305 {
306 parent::init();
307 if($this->autoConnect)
308 $this->setActive(true);
309 }
310
311 /**
312 * Returns whether the DB connection is established.
313 * @return boolean whether the DB connection is established

#2

C:\wamp\www\app\protected\vendors\Yii\base\CModule.php(387): CDbConnection->init()

382 if(!isset($config['enabled']) || $config['enabled'])
383 {
384 Yii::trace("Loading \"$id\" application component",'system.CModule');
385 unset($config['enabled']);
386 $component=Yii::createComponent($config);
387 $component->init();
388 return $this->_components[$id]=$component;
389 }
390 }
391 }
392

#3

C:\wamp\www\app\protected\vendors\Yii\web\auth\CDbAuthManager.php(589): CModule->getComponent("db")

584 */
585 protected function getDbConnection()
586 {
587 if($this->db!==null)
588 return $this->db;
589 elseif(($this->db=Yii::app()->getComponent($this->connectionID)) instanceof CDbConnection)
590 return $this->db;
591 else
592 throw new CException(Yii::t('yii','CDbAuthManager.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.',
593 array('{id}'=>$this->connectionID)));
594 }

#4

C:\wamp\www\app\protected\vendors\Yii\web\auth\CDbAuthManager.php(59): CDbAuthManager->getDbConnection()

54 * This method overrides the parent implementation by establishing the database connection.
55 */
56 public function init()
57 {
58 parent::init();
59 $this->_usingSqlite=!strncmp($this->getDbConnection()->getDriverName(),'sqlite',6);
60 }
61
62 /**
63 * Performs access check for the specified user.
64 * @param string $itemName the name of the operation that need access check

#5

C:\wamp\www\app\protected\vendors\Yii\base\CModule.php(387): CDbAuthManager->init()

382 if(!isset($config['enabled']) || $config['enabled'])
383 {
384 Yii::trace("Loading \"$id\" application component",'system.CModule');
385 unset($config['enabled']);
386 $component=Yii::createComponent($config);
387 $component->init();
388 return $this->_components[$id]=$component;
389 }
390 }
391 }
392

#6

C:\wamp\www\app\protected\vendors\Yii\web\CWebApplication.php(185): CModule->getComponent("authManager")

180 /**
181 * @return IAuthManager the authorization manager component
182 */
183 public function getAuthManager()
184 {
185 return $this->getComponent('authManager');
186 }
187
188 /**
189 * @return CAssetManager the asset manager component
190 */

#7

C:\wamp\www\app\protected\vendors\Yii\web\auth\CWebUser.php(815): CWebApplication->getAuthManager()

810 public function checkAccess($operation,$params=array(),$allowCaching=true)
811 {
812 if($allowCaching && $params===array() && isset($this->_access[$operation]))
813 return $this->_access[$operation];
814
815 $access=Yii::app()->getAuthManager()->checkAccess($operation,$this->getId(),$params);
816 if($allowCaching && $params===array())
817 $this->_access[$operation]=$access;
818
819 return $access;
820 }

#8

C:\wamp\www\app\protected\modules\auth\components\AuthWebUser.php(59): CWebUser->checkAccess("customerRequest", array(), true)

54 public function checkAccess($operation, $params = array(), $allowCaching = true) {
55 if ($this->getIsAdmin()) {
56 return true;
57 }
58
59 return parent::checkAccess($operation, $params, $allowCaching);
60 }
61 }

#9

C:\wamp\www\app\protected\views\layouts\main.php(52): AuthWebUser->checkAccess("customerRequest")

47 array(
48 'class' => 'bootstrap.widgets.TbMenu',
49 'items' => array(
50 array('label' => Yii::t('app', 'Home'), 'url' => array('/site/index')),
51 array('label' => Yii::t('app', 'Application'), 'visible' => !Yii::app()->user->isGuest, 'items' => array(
52 array('label' => Yii::t('app', 'Requests'), 'url' => array('/customerRequest'), 'visible' => Yii::app()->user->checkAccess('customerRequest')),
53 array('label' => Yii::t('app', 'Customers'), 'url' => array('/customer'), 'visible' => Yii::app()->user->checkAccess('customer')),
54 array('label' => Yii::t('app', 'Packages'), 'url' => array('/package'), 'visible' => Yii::app()->user->checkAccess('package')),
55 )),
56 array('label' => Yii::t('app', 'Tools'), 'visible' => Yii::app()->user->checkAccess('tools'), 'items' => array(
57 array('label' => Yii::t('app', 'Users'), 'url' => array('/user'), 'visible' => Yii::app()->user->checkAccess('user')),






#10

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(126): require("C:\wamp\www\app\protected\views\layouts\main.php")

121 $data=$_data_;
122 if($_return_)
123 {
124 ob_start();
125 ob_implicit_flush(false);
126 require($_viewFile_);
127 return ob_get_clean();
128 }
129 else
130 require($_viewFile_);
131 }

#11

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(95): CBaseController->renderInternal("C:\wamp\www\app\protected\views//layouts/main.php", array("content" => " <div id="content"> <div class="box"> <di..."), true)

090 {
091 $widgetCount=count($this->_widgetStack);
092 if(($renderer=Yii::app()->getViewRenderer())!==null && $renderer->fileExtension==='.'.CFileHelper::getExtension($viewFile))
093 $content=$renderer->renderFile($this,$viewFile,$data,$return);
094 else
095 $content=$this->renderInternal($viewFile,$data,$return);
096 if(count($this->_widgetStack)===$widgetCount)
097 return $content;
098 else
099 {
100 $widget=end($this->_widgetStack);

#12

C:\wamp\www\app\protected\vendors\Yii\web\widgets\CContentDecorator.php(76): CBaseController->renderFile("C:\wamp\www\app\protected\views//layouts/main.php", array("content" => " <div id="content"> <div class="box"> <di..."), true)

71 $viewFile=$owner->getViewFile($this->view);
72 if($viewFile!==false)
73 {
74 $data=$this->data;
75 $data['content']=$content;
76 return $owner->renderFile($viewFile,$data,true);
77 }
78 else
79 return $content;
80 }
81 }

#13

C:\wamp\www\app\protected\vendors\Yii\web\widgets\CContentDecorator.php(54): CContentDecorator->decorate(" <div id="content"> <div class="box"> <di...")

49 * This method decorates the output with the specified {@link view}.
50 * @param string $output the captured output to be processed
51 */
52 public function processOutput($output)
53 {
54 $output=$this->decorate($output);
55 parent::processOutput($output);
56 }
57
58 /**
59 * Decorates the content by rendering a view and embedding the content in it.

#14

C:\wamp\www\app\protected\vendors\Yii\web\widgets\COutputProcessor.php(44): CContentDecorator->processOutput(" <div id="content"> <div class="box"> <di...")

39 * This method stops output buffering and processes the captured output.
40 */
41 public function run()
42 {
43 $output=ob_get_clean();
44 $this->processOutput($output);
45 }
46
47 /**
48 * Processes the captured output.
49 *

#15

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(206): COutputProcessor->run()

201 */
202 public function endWidget($id='')
203 {
204 if(($widget=array_pop($this->_widgetStack))!==null)
205 {
206 $widget->run();
207 return $widget;
208 }
209 else
210 throw new CException(Yii::t('yii','{controller} has an extra endWidget({id}) call in its view.',
211 array('{controller}'=>get_class($this),'{id}'=>$id)));



#16

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(300): CBaseController->endWidget("CContentDecorator")

295 * Ends the rendering of content.
296 * @see beginContent
297 */
298 public function endContent()
299 {
300 $this->endWidget('CContentDecorator');
301 }
302 }

#17

C:\wamp\www\app\protected\views\layouts\column1.php(6): CBaseController->endContent()

1 <?php /* @var $this Controller */ ?>
2 <?php $this->beginContent('//layouts/main'); ?>
3 <div id="content">
4 <?php echo $content; ?>
5 </div><!-- content -->
6 <?php $this->endContent(); ?>

#18

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(126): require("C:\wamp\www\app\protected\views\layouts\column1.php")

121 $data=$_data_;
122 if($_return_)
123 {
124 ob_start();
125 ob_implicit_flush(false);
126 require($_viewFile_);
127 return ob_get_clean();
128 }
129 else
130 require($_viewFile_);
131 }


#19

C:\wamp\www\app\protected\vendors\Yii\web\CBaseController.php(95): CBaseController->renderInternal("C:\wamp\www\app\protected\views//layouts/column1.php", array("content" => " <div class="box"> <div class="page-header"> ..."), true)

090 {
091 $widgetCount=count($this->_widgetStack);
092 if(($renderer=Yii::app()->getViewRenderer())!==null && $renderer->fileExtension==='.'.CFileHelper::getExtension($viewFile))
093 $content=$renderer->renderFile($this,$viewFile,$data,$return);
094 else
095 $content=$this->renderInternal($viewFile,$data,$return);
096 if(count($this->_widgetStack)===$widgetCount)
097 return $content;
098 else
099 {
100 $widget=end($this->_widgetStack);

#20

C:\wamp\www\app\protected\vendors\Yii\web\CController.php(784): CBaseController->renderFile("C:\wamp\www\app\protected\views//layouts/column1.php", array("content" => " <div class="box"> <div class="page-header"> ..."), true)

779 {
780 if($this->beforeRender($view))
781 {
782 $output=$this->renderPartial($view,$data,true);
783 if(($layoutFile=$this->getLayoutFile($this->layout))!==false)
784 $output=$this->renderFile($layoutFile,array('content'=>$output),true);
785
786 $this->afterRender($view,$output);
787
788 $output=$this->processOutput($output);
789

#21

C:\wamp\www\app\protected\controllers\SiteController.php(96): CController->render("login", array("model" => LoginForm))

091 } else {
092 Yii::app()->user->setFlash('error', Yii::t('app', '<strong>Oh snap!</strong> Login faild. Please try again.'));
093 }
094 }
095 // display the login form
096 $this->render('login', array('model' => $model));
097 }
098
099 /**
100 * Logs out the current user and redirect to homepage.
101 */

#22

C:\wamp\www\app\protected\vendors\Yii\web\actions\CInlineAction.php(49): SiteController->actionLogin()

44 $controller=$this->getController();
45 $method=new ReflectionMethod($controller, $methodName);
46 if($method->getNumberOfParameters()>0)
47 return $this->runWithParamsInternal($controller, $method, $params);
48 else
49 return $controller->$methodName();
50 }
51
52 }

#23

C:\wamp\www\app\protected\vendors\Yii\web\CController.php(308): CInlineAction->runWithParams(array())

303 {
304 $priorAction=$this->_action;
305 $this->_action=$action;
306 if($this->beforeAction($action))
307 {
308 if($action->runWithParams($this->getActionParams())===false)
309 $this->invalidActionParams($action);
310 else
311 $this->afterAction($action);
312 }
313 $this->_action=$priorAction;

#24

C:\wamp\www\app\protected\vendors\Yii\web\CController.php(286): CController->runAction(CInlineAction)

281 * @see runAction
282 */
283 public function runActionWithFilters($action,$filters)
284 {
285 if(empty($filters))
286 $this->runAction($action);
287 else
288 {
289 $priorAction=$this->_action;
290 $this->_action=$action;
291 CFilterChain::create($this,$action,$filters)->run();

#25

C:\wamp\www\app\protected\vendors\Yii\web\CController.php(265): CController->runActionWithFilters(CInlineAction, array())

260 {
261 if(($parent=$this->getModule())===null)
262 $parent=Yii::app();
263 if($parent->beforeControllerAction($this,$action))
264 {
265 $this->runActionWithFilters($action,$this->filters());
266 $parent->afterControllerAction($this,$action);
267 }
268 }
269 else
270 $this->missingAction($actionID);

#26

C:\wamp\www\app\protected\vendors\Yii\web\CWebApplication.php(282): CController->run("")

277 {
278 list($controller,$actionID)=$ca;
279 $oldController=$this->_controller;
280 $this->_controller=$controller;
281 $controller->init();
282 $controller->run($actionID);
283 $this->_controller=$oldController;
284 }
285 else
286 throw new CHttpException(404,Yii::t('yii','Unable to resolve the request "{route}".',
287 array('{route}'=>$route===''?$this->defaultController:$route)));

#27

C:\wamp\www\app\protected\components\WebApplication.php(33): CWebApplication->runController("")

28 * that Apache polls its processes to see if they're alive. This function causes
29 * Yii to respond without logging errors.
30 */
31 public function runController($route) {
32 try {
33 parent::runController($route);
34 } catch (CHttpException $e) {
35 if (@$_SERVER['REQUEST_METHOD'] == 'OPTIONS' && @$_SERVER['REQUEST_URI'] == '*') {
36 Yii::app()->end('Bye, bye!');
37 } else
38 throw $e;

#28

C:\wamp\www\app\protected\vendors\Yii\web\CWebApplication.php(141): WebApplication->runController("")

136 foreach(array_splice($this->catchAllRequest,1) as $name=>$value)
137 $_GET[$name]=$value;
138 }
139 else
140 $route=$this->getUrlManager()->parseUrl($this->getRequest());
141 $this->runController($route);
142 }
143
144 /**
145 * Registers the core application components.
146 * This method overrides the parent implementation by registering additional core components.

#29

C:\wamp\www\app\protected\vendors\Yii\base\CApplication.php(180): CWebApplication->processRequest()

175 public function run()
176 {
177 if($this->hasEventHandler('onBeginRequest'))
178 $this->onBeginRequest(new CEvent($this));
179 register_shutdown_function(array($this,'end'),0,false);
180 $this->processRequest();
181 if($this->hasEventHandler('onEndRequest'))
182 $this->onEndRequest(new CEvent($this));
183 }
184
185 /**

#30

C:\wamp\www\app\index.php(15): CApplication->run()

10 $env->init();
11 //$env->showDebug();
12
13 require_once(dirname(__FILE__).'/protected/components/WebApplication.php');
14 $app = new WebApplication($env->web);
15 $app->run();


Mamma Mia
mlawnik
Kod
CDbConnection.connectionString cannot be empty.


Złe ustawienia bazy danych.
I na następny raz użyj tagu code albo pastebina jakiegoś, jak ktoś wejdzie i zobaczy taką bezmyślnie wklejoną kupę błędów to od razu wyjdzie.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.