1

I'm getting nowhere with MS Sql and some php queries.

function getBillet($idBillet) {

    $connection = getBdd();
    $sql = 'select BIL_ID as id, BIL_DATE as date,
      BIL_TITRE as titre, BIL_CONTENU as contenu from t_billet
       where BIL_ID=?';
    $billet = $connection->prepare($sql);
    $billet->execute(array($idBillet));

    if ($billet->rowCount() == 1)
        return $billet->fetch();
    else
        throw new Exception('Aucun billet ne correspond à l\'identifiant' . $idBillet . ' ');
}

This one is not working, i'm trying to fetch the row with the ID inserted on parameter. The connection to the database works fine, but I can't get the query to work. Especially since all the information on google is about MySQL but very few about MS SQL. This one works fine for example :

function getBillets() {
$connection = getBdd();
$sql = 'select BIL_ID as id, BIL_DATE as date,
      BIL_TITRE as titre, BIL_CONTENU as contenu from t_billet
       order by BIL_ID desc';
$result = $connection->query($sql);
$resultat = $result->fetchAll();

return $resultat;
}

Thanks in advance.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
aydos
  • 31
  • 3
  • _This one is not working_ How? Giving errors? Giving something you dont expect? Not giving you what you do expect? – RiggsFolly Jul 05 '17 at 21:45
  • What does _not working_ mean? Does it return anything, throw an exception? – AbraCadaver Jul 05 '17 at 21:46
  • It doesn't show anything, not an error nor any result. – aydos Jul 05 '17 at 21:47
  • Have you tried simply testing IF the prepare and execute are returning false and if so outputting the database error – RiggsFolly Jul 05 '17 at 21:48
  • It might be useful to see how you connect to the database – RiggsFolly Jul 05 '17 at 21:49
  • Yea I just tried testing with IF and both prepare and execute returns true. So the problem is not the query ? Can't find the problem :\ – aydos Jul 05 '17 at 22:01
  • The first one is wanting a parameter, did you pass SQL the parameter via PHP? – Chuck Jul 05 '17 at 22:11
  • What OS are you using? What driver are you using (ODBC, Sybase, etc)? What version of PHP? I feel your pain with a variety of MSSQL issues such as [here](https://stackoverflow.com/q/38255659/4233593) and [here](https://stackoverflow.com/q/39044034/4233593) and [here](https://stackoverflow.com/q/40116280/4233593). – Jeff Puckett Jul 06 '17 at 03:53

0 Answers0