Bonjour, ce matin en arrivant dans les vingtaines de minutes de vidéo, je tombe sur une erreur :

( ! ) SCREAM: Error suppression ignored for
( ! ) Notice: Undefined variable: db in C:\wamp\www\Tuto\core\Model.php on line 7
Call Stack

Time Memory Function Location

1 0.0010 143624 {main}( ) ..\index.php:0
2 0.0176 173384 Dispatcher->__construct( ) ..\index.php:10
3 0.0181 177968 call_user_func_array ( ) ..\Dispatcher.php:13
4 0.0181 178064 PagesController->view( ) ..\Dispatcher.php:13
5 0.0181 178136 Controller->loadModel( ) ..\PagesController.php:6
6 0.0185 179600 Model->__construct( ) ..\Controller.php:61

( ! ) SCREAM: Error suppression ignored for
( ! ) Fatal error: Cannot access empty property in C:\wamp\www\Tuto\core\Model.php on line 7
Call Stack

Time Memory Function Location

1 0.0010 143624 {main}( ) ..\index.php:0
2 0.0176 173384 Dispatcher->__construct( ) ..\index.php:10
3 0.0181 177968 call_user_func_array ( ) ..\Dispatcher.php:13
4 0.0181 178064 PagesController->view( ) ..\Dispatcher.php:13
5 0.0181 178136 Controller->loadModel( ) ..\PagesController.php:6
6 0.0185 179600 Model->__construct( ) ..\Controller.php:61

Voici mes lignes de code du model.php :

<?php
class Model{

    public $db = 'default';

    public function __construct(){
        $conf = Conf::$databases$this->$db];
        try{
            $db = new PDO('mysql:host='.$conf'host'].'dbname='.$conf'database'].';',$conf'login'],$conf'password']);
        }catch(PDOException $e){
            die(print_r($e,true));
        }
    }
    public function find(){
    }

}
?>

D'où viendrai mon erreur svp ?

Merci d'avance pour vos futurs réponses :)

8 réponses


Tackacoder
Réponse acceptée

J'ai fait ça salement, corrige avec

$db = new PDO('mysql:dbname='.$conf'database'].';host='.$conf'host'], $conf'login'], $conf'password']);

Salut,
Ce n'est pas plutôt

$conf = Conf::$databases$this->db];

au lieu de

$conf = Conf::$databases$this->$db];

Enfin je crois !

Romain72
Auteur

Après celà, ça me marque: ( ! ) SCREAM: Error suppression ignored for ( ! ) Notice: Undefined index: database in C:\wamp\www\Tuto\core\Model.php on line 9 Call Stack # Time Memory Function Location 1 0.0007 143624 {main}( ) ..\index.php:0 2 0.0030 173424 Dispatcher->__construct( ) ..\index.php:10 3 0.0230 178008 call_user_func_array ( ) ..\Dispatcher.php:13 4 0.0230 178104 PagesController->view( ) ..\Dispatcher.php:13 5 0.0230 178176 Controller->loadModel( ) ..\PagesController.php:6 6 0.0238 179640 Model->__construct( ) ..\Controller.php:61 ( ! ) SCREAM: Error suppression ignored for ( ! ) Warning: PDO::__construct(): in C:\wamp\www\Tuto\core\Model.php on line 9 Call Stack # Time Memory Function Location 1 0.0007 143624 {main}( ) ..\index.php:0 2 0.0030 173424 Dispatcher->__construct( ) ..\index.php:10 3 0.0230 178008 call_user_func_array ( ) ..\Dispatcher.php:13 4 0.0230 178104 PagesController->view( ) ..\Dispatcher.php:13 5 0.0230 178176 Controller->loadModel( ) ..\PagesController.php:6 6 0.0238 179640 Model->__construct( ) ..\Controller.php:61 7 0.0564 180000 PDO->__construct( ) ..\Model.php:9 PDOException Object ( [message:protected] => SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Hôte inconnu. [string:Exception:private] => [code:protected] => 2002 [file:protected] => C:\wamp\www\Tuto\core\Model.php [line:protected] => 9 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\Tuto\core\Model.php [line] => 9 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhostdbname=; [1] => root [2] => ) ) [1] => Array ( [file] => C:\wamp\www\Tuto\core\Controller.php [line] => 61 [function] => __construct [class] => Model [type] => -> [args] => Array ( ) ) [2] => Array ( [file] => C:\wamp\www\Tuto\controller\PagesController.php [line] => 6 [function] => loadModel [class] => Controller [type] => -> [args] => Array ( [0] => Post ) ) [3] => Array ( [function] => view [class] => PagesController [type] => -> [args] => Array ( ) ) [4] => Array ( [file] => C:\wamp\www\Tuto\core\Dispatcher.php [line] => 13 [function] => call_user_func_array [args] => Array ( [0] => Array ( [0] => PagesController Object ( [request] => Request Object ( [url] => /pages/view [controller] => pages [action] => view [params] => Array ( ) ) [vars:Controller:private] => Array ( ) [layout] => default [rendered:Controller:private] => ) [1] => view ) [1] => Array ( ) ) ) [5] => Array ( [file] => C:\wamp\www\Tuto\webroot\index.php [line] => 10 [function] => __construct [class] => Dispatcher [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => [errorInfo] => [xdebug_message] => ( ! ) PDOException: in C:\wamp\www\Tuto\core\Model.php on line 9 Call Stack #TimeMemoryFunctionLocation 10.0007143624{main}( )..\index.php:0 20.0030173424Dispatcher->__construct( )..\index.php:10 30.0230178008call_user_func_array ( )..\Dispatcher.php:13 40.0230178104PagesController->view( )..\Dispatcher.php:13 50.0230178176Controller->loadModel( )..\PagesController.php:6 60.0238179640Model->__construct( )..\Controller.php:61 70.0564180000PDO->__construct( )..\Model.php:9 )

Bonjour, c'est un problème dans ton array $conf.
Que renvoie $conf ?

Romain72
Auteur

Donc, j'ai déjà rajouté un "s" à databases, celà m'a supprimer une ereur, merci exothermique de m'avoir mis sur la piste ;) mais voilà, toujours une erreur reste là : SCREAM: Error suppression ignored for ( ! ) Warning: PDO::__construct(): in C:\wamp\www\Tuto\core\Model.php on line 9 Call Stack # Time Memory Function Location 1 0.0003 143864 {main}( ) ..\index.php:0 2 0.0025 173664 Dispatcher->__construct( ) ..\index.php:10 3 0.0028 178248 call_user_func_array ( ) ..\Dispatcher.php:13 4 0.0028 178344 PagesController->view( ) ..\Dispatcher.php:13 5 0.0028 178416 Controller->loadModel( ) ..\PagesController.php:6 6 0.0031 179880 Model->__construct( ) ..\Controller.php:61 7 0.0031 180248 PDO->__construct( ) ..\Model.php:9 PDOException Object ( [message:protected] => SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Hôte inconnu. [string:Exception:private] => [code:protected] => 2002 [file:protected] => C:\wamp\www\Tuto\core\Model.php [line:protected] => 9 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\wamp\www\Tuto\core\Model.php [line] => 9 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:host=localhostdbname=tuto; [1] => root [2] => ) ) [1] => Array ( [file] => C:\wamp\www\Tuto\core\Controller.php [line] => 61 [function] => __construct [class] => Model [type] => -> [args] => Array ( ) ) [2] => Array ( [file] => C:\wamp\www\Tuto\controller\PagesController.php [line] => 6 [function] => loadModel [class] => Controller [type] => -> [args] => Array ( [0] => Post ) ) [3] => Array ( [function] => view [class] => PagesController [type] => -> [args] => Array ( ) ) [4] => Array ( [file] => C:\wamp\www\Tuto\core\Dispatcher.php [line] => 13 [function] => call_user_func_array [args] => Array ( [0] => Array ( [0] => PagesController Object ( [request] => Request Object ( [url] => /pages/view [controller] => pages [action] => view [params] => Array ( ) ) [vars:Controller:private] => Array ( ) [layout] => default [rendered:Controller:private] => ) [1] => view ) [1] => Array ( ) ) ) [5] => Array ( [file] => C:\wamp\www\Tuto\webroot\index.php [line] => 10 [function] => __construct [class] => Dispatcher [type] => -> [args] => Array ( ) ) ) [previous:Exception:private] => [errorInfo] => [xdebug_message] => ( ! ) PDOException: in C:\wamp\www\Tuto\core\Model.php on line 9 Call Stack #TimeMemoryFunctionLocation 10.0003143864{main}( )..\index.php:0 20.0025173664Dispatcher->__construct( )..\index.php:10 30.0028178248call_user_func_array ( )..\Dispatcher.php:13 40.0028178344PagesController->view( )..\Dispatcher.php:13 50.0028178416Controller->loadModel( )..\PagesController.php:6 60.0031179880Model->__construct( )..\Controller.php:61 70.0031180248PDO->__construct( )..\Model.php:9 ) Voici mon conf.php : [code]<?php class Conf{

static $databases = array(

    'default' => array( 'host' => 'localhost', 'databases' => 'tuto', 'login' => 'root', 'password' => '' ) ); }[/code]

Je crois que tu as des problèmes de points virgule et virgules.
remplace

$db = new PDO('mysql:host='.$conf'host'].'dbname='.$conf'database'].';',$conf'login'],$conf'password']);

par

$db = new PDO('mysql:dbname='.$conf'database'].';host='.$conf'host'].',$conf'login'],$conf'password']);
Romain72
Auteur

Merci de m'avoir aidé, celà m'a bien éclaircit dans mes erreur, mais toujour une erreur reste là :
( ! ) SCREAM: Error suppression ignored for
( ! ) Parse error: syntax error, unexpected 'login' (T_STRING) in C:\wamp\www\Tuto\core\Model.php on line 9
Call Stack

Time Memory Function Location

1 0.0271 143864 {main}( ) ..\index.php:0
2 0.0281 146360 require( 'C:\wamp\www\Tuto\core\Includes.php' ) ..\index.php:8

Sinon, il n'y a pas une erreur dans ta ligne ?

$db = new PDO('mysql:dbname='.$conf'database'].';host='.$conf'host'].',$conf'login'],$conf'password']);

ce n'est pas plutot ça?

$db = new PDO('mysql:dbname='.$conf'database'].';host='.$conf'host'].','$conf'login'],$conf'password']);

Mais en rajoutant ce détail ou en l'enlevant, je tombe toujours à la même erreur cité juste au dessus

Romain72
Auteur

Voilà merci d'avoir corriger mes erreurs :)