0

I have connected the sql database server using FreeTDS in php. I am trying to execute sql select query in php. I can't able to execute query. I mentioned the program below

 <?php
    $empid = 10068;
    try
    {
        $db = new PDO('odbc:Driver=FreeTDS; Server=XXXXXXX; Port=1433; Database=XXXX; UID=XXXXXX; PWD=XXXXX;');
    }
    catch(PDOException $exception)
    {
        die("Unable to open database.<br />Error message:<br /><br />$exception.");
    }
    echo '<h1>Successfully connected!</h1>';
    echo gettype($empid);
    $query = "select Employee_ID from REPT_Employee where Employee_ID=$empid";
    echo $query
    **$statement = $db->prepare($query);** //Getting error in this line
    $statement->execute();
    $result = $statement->fetchAll(PDO::FETCH_NUM);
    echo $result 
 ?>

I Can't able to execute the query. Can anyone help me to find out what mistake i did.

Python Team
  • 1,143
  • 4
  • 21
  • 50

2 Answers2

0

To change like this

 $statement = $db->query("select Password from REPT_Employee where Employee_ID=$empid");
 $statement->execute();
Python Team
  • 1,143
  • 4
  • 21
  • 50
0

if you don't use the bindParam function you have to use prepare function in this way :

$statement = $db->prepare("select Employee_ID from REPT_Employee where Employee_ID='$empid'");

Just add quotes '' to $empid string in the $query string.

Davide
  • 113
  • 2
  • 11
  • Try to use `bindParam` function : `$statement = $db->prepare("select Employee_ID from REPT_Employee where Employee_ID=:empid"); $statement->bindParam(":empid",$empid); $statement->execute();` – Davide Jun 25 '14 at 11:17