IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Zend_Db PHP Discussion :

select() on a non-object


Sujet :

Zend_Db PHP

  1. #1
    Membre régulier Avatar de Lost In Translation
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    166
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Mai 2007
    Messages : 166
    Points : 89
    Points
    89
    Par défaut select() on a non-object
    Coucou,

    J'essaie de créer un modèle pour mon application ZF. J'obtiens une erreur lors de la création d'une requête de type select.

    `Fatal error: Call to a member function select() on a non-object in [...]/models/TrackingPageMapper.php on line 86`

    Je suis un nouvel utilisateur dans ZF.

    Voici mon morceau de code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    class Default_Model_TrackingPageMapper
        {
    	    private $_db;
     
    	/**
    	 * __construct
    	 */
    	public function __construct() 
    	{
    		$_db = Zend_Db_Table::getDefaultAdapter();
    	}
     
    	#-----[Public Section]
     
    	/**
    	 * addView()
    	 * @param EtId, etablissement id
    	 * 
    	 * Check :
    	 * 1) If this is the first click of the day for this IP on this page
    	 * 2) If this is the first click of the month for this IP
    	 * 3) Save or not
    	 * 
    	 * @return void
    	 * 
    	 */
    	public function addView($EtId)
    	{
    		$today = getDate();
    		$ip = $this->getRealIp();
     
    		//Check If is the IP exists
    		$this->ipExists($ip, $EtId);
     
    		//print_r($today);
     
     
     
     
    	}
     
    	#-----[Private Section]
     
    	/**
    	 * getRealIp()
    	 * @return varchar(15)
    	 * 
    	 */
    	private function getRealIp()
    	{
    	    if (!empty($_SERVER['HTTP_CLIENT_IP']))
    	    {
    	      $ip = $_SERVER['HTTP_CLIENT_IP'];
    	    }
    	    elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR']))
    	    {
    	      $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    	    }
    	    else
    	    {
    	      $ip = $_SERVER['REMOTE_ADDR'];
    	    }
     
    	    return $ip;
    	}
     
    	/**
    	 * ipExists()
    	 * @param Ip address
    	 * @param EtId, etablissement id
    	 * 
    	 * @return false if ip !exists
    	 * @return array of ip infos if exists
    	 * 
    	 */
    	public function ipExists($Ip, $EtId = null)
    	{
    		$myQuery = $this->_db->select()
    							 ->from('tracking_ip', 'idtracking_ip')
    							 ->where('ip = ?',$Ip);
     
    		$result = $this->_db->fetchAll($myQuery);
     
    		print_r($result);
    	}
        }
    Et j'appelle mon modèle dans mon controller de cette façon :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     $oTrack = new Default_Model_TrackingPageMapper;
        $oTrack->addView($Id);
    le var_dump de mon objet DB donne ceci :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    var_dump($_db);
     
        object(Zend_Db_Adapter_Pdo_Mysql)#76 (12) {
          ["_pdoType":protected]=>
          string(5) "mysql"
          ["_numericDataTypes":protected]=>
          array(16) {
            [0]=>
            int(0)
            [1]=>
            int(1)
            [2]=>
            int(2)
            ["INT"]=>
            int(0)
            ["INTEGER"]=>
            int(0)
            ["MEDIUMINT"]=>
            int(0)
            ["SMALLINT"]=>
            int(0)
            ["TINYINT"]=>
            int(0)
            ["BIGINT"]=>
            int(1)
            ["SERIAL"]=>
            int(1)
            ["DEC"]=>
            int(2)
            ["DECIMAL"]=>
            int(2)
            ["DOUBLE"]=>
            int(2)
            ["DOUBLE PRECISION"]=>
            int(2)
            ["FIXED"]=>
            int(2)
            ["FLOAT"]=>
            int(2)
          }
          ["_defaultStmtClass":protected]=>
          string(21) "Zend_Db_Statement_Pdo"
          ["_config":protected]=>
          array(7) {
            ["username"]=>
            string(4) "riad"
            ["password"]=>
            string(7) "xxxxxx"
            ["dbname"]=>
            string(8) "riad_dev"
            ["charset"]=>
            string(4) "utf8"
            ["driver_options"]=>
            array(1) {
              [1002]=>
              string(14) "SET NAMES utf8"
            }
            ["persistent"]=>
            bool(false)
            ["options"]=>
            array(3) {
              ["caseFolding"]=>
              int(0)
              ["autoQuoteIdentifiers"]=>
              bool(true)
              ["fetchMode"]=>
              int(2)
            }
          }
          ["_fetchMode":protected]=>
          int(2)
          ["_profiler":protected]=>
          object(Zend_Db_Profiler)#74 (4) {
             ["_queryProfiles":protected]=>
             array(0) {
             }
            ["_enabled":protected]=>
            bool(false)
            ["_filterElapsedSecs":protected]=>
            NULL
            ["_filterTypes":protected]=>
            NULL
          }
          ["_defaultProfilerClass":protected]=>
          string(16) "Zend_Db_Profiler"
          ["_connection":protected]=>
          NULL
          ["_caseFolding":protected]=>
          int(0)
          ["_autoQuoteIdentifiers":protected]=>
          bool(true)
          ["_allowSerialization":protected]=>
          bool(true)
          ["_autoReconnectOnUnserialize":protected]=>
          bool(false)
           }
    Quelqu'un peut m'aider ?
    Merci pour vos aides à venir,

  2. #2
    Membre régulier Avatar de Lost In Translation
    Profil pro
    Inscrit en
    Mai 2007
    Messages
    166
    Détails du profil
    Informations personnelles :
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Mai 2007
    Messages : 166
    Points : 89
    Points
    89
    Par défaut
    J'ai écrit $_db au lieu de $this->_db dans mon constructeur... quel gland XD !

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 9
    Dernier message: 05/07/2007, 11h25
  2. [POO] Call to a member function on a non-object
    Par Roromix dans le forum Langage
    Réponses: 3
    Dernier message: 25/04/2007, 14h40
  3. [phpToPDF] "Call to a member function on a non-object"
    Par pikatshu dans le forum Bibliothèques et frameworks
    Réponses: 3
    Dernier message: 16/04/2007, 18h47
  4. [POO] Erreur Trying to get property of non-object
    Par Niouts dans le forum Langage
    Réponses: 14
    Dernier message: 13/09/2006, 10h09
  5. Select avec écriture non bloquante
    Par Invité dans le forum Réseau
    Réponses: 5
    Dernier message: 24/05/2006, 16h20

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo