vendredi 8 mai 2015

Select data using PDO and a PHP function

When I try to select one nome from my bd it doesn't show anything

That's the function to select a name:

public function searchName(){
    $db = new Conection();
    $query = $db->prepare("SELECT * FROM dog WHERE id = 1");
    $query->execute();
    $result = $query->fetchAll(PDO::FETCH_OBJ);
    foreach($result as $row)
    {
        return $row['name'];//return to getName

    }
}

here is the code from getName:

    require 'Conection.php';
    require 'model/Dog.php';

    $dog = new Dog;
    $res = $dog->searchName(1);

    echo $res;

The class Connection is ok.

Aucun commentaire:

Enregistrer un commentaire