Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 23
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803

    PDO in query genera errore warning

    salve ragazzi sto cercando di aggiornarmi con le nuove tecniche di connessione , ho scielto PDO , e nei vari tentativi mi genera qualche errore ! tipo :
    Codice PHP:
    $dsn "mysql:host=localhost;dbname=xxx";  
    $username "root";  
    $pass "";    
    $PDO = new PDO($dsn$username$pass);  
    $PDO->query("SELECT * FROM  pages")or die();
     while(
    $row $PDO->fetch(PDO::FETCH_ASSOC)) 
     {
        echo 
    $row['nome_pages'].'<br>'
        } 
    genera il seguente errore :
    codice:
    Fatal error: Call to undefined method PDO::fetch() in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\hindex.php on line 17
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803
    problema risolto grazie ugualmente
    Codice PHP:
    $result $PDO->query("SELECT * FROM  pages")or die();
    while(
    $row $result->fetch()) 
    {
        echo 
    $row['nome_pages'].'<br>'

    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803
    rimango con un problema , cerco di riadattare la mia classe , pero mi da errori:
    Codice PHP:

    function connect()
    {
    try 
    {
    $this->db_core  = new PDO$this->db_type .":host=".$this->db_host";dbname=".$this->db_name.""$this->db_user$this->db_pass , array(PDO::ATTR_PERSISTENT=>$this->db_persistent));   
         if(!
    $this->db_core )
         {
               return 
    false;
         }
        
    /* print_r($this->db_core);  */
    } catch(PDOException $e
    {
         if(
    $e->getMessage() )
         {
               return 
    false;
         }
       return 
    true;
      }
    }


    function 
    query($sql
    {
    global 
    $RCW ;


    $result =  $this->db_core->query($sql $this->db_core);
     
     if(!
    $result)
     {
       return 
    false;
     }
     return 
    $result;

    perche cosa sbaglio ?
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  4. #4
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    Sbagli nel non dire gli errori.
    Oppure è un quiz e dobbiamo indovinare?

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803
    ciao ecco gli errori :Warning: PDO::query() expects parameter 1 to be string, object given in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\cms\class\dbclass.php on line 108

    Fatal error: Call to a member function fetchColumn() on a non-object in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\cms\class\dbclass.php on line 109
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  6. #6
    Utente di HTML.it
    Registrato dal
    Feb 2014
    residenza
    Voltati
    Messaggi
    913
    Quali sono le righe 108 e 109?
    No

  7. #7
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803
    ciao sono parecchi errori , momentaneamente mi da questo Fatal error: Call to a member function fetch() on a non-object in C:\Program Files\EasyPHP-DevServer-14.1VC11\data\localweb\cms\class\dbclass.php on line 84

    function getquery($sql)
    {
    $result = $this->query($sql);
    $returned = $result->fetch(PDO::FETCH_ASSOC);
    /* $result->closeCursor(); */
    return $returned;
    }
    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

  8. #8
    Moderatore di PHP L'avatar di Alhazred
    Registrato dal
    Oct 2003
    Messaggi
    12,505
    A occhio non ce le ha messe nel codice postato, non c'è da nessuna parte fetchColumn()

  9. #9
    Utente di HTML.it
    Registrato dal
    Feb 2014
    residenza
    Voltati
    Messaggi
    913
    Beh, l'errore dice tutto quello che devi sapere: $result non è un oggetto
    No

  10. #10
    Utente di HTML.it
    Registrato dal
    May 2007
    Messaggi
    1,803
    sempre il solito problema con questa funzione
    Codice PHP:
     function querycount($sql
    {
      
    $this->result $this->query($sql);
      if(!
    $this->result)
      {
      return 
    false;
      }
      
    $this->resultate $this->result->rowCount();
      return 
    $this->resultate;

    Non è tanto importante saper fare,quanto ad avere voglia d imparare .

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.