Search code examples
phpmysqlbindparam

Not Getting Any Results with Query


I am having getting my query to display results, I have ran the exact same query locally in mySQL and I get the desired result but when it is executed through the following code nothing happens.

$JobID = '3214.GF.010.J45.TEA';
$ProjectID = '3214';    
$conn = new mysqli ($server,$username,$password,$dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully <br>";
$stmt = $conn->prepare('Select jmpPartShortDescription, ujmpLevel, ujmpRoom, jmpClosed from Inf_Jobs');
//$stmt->bind_param('ss',$JobID,$ProjectID);
$stmt -> bind_result($Description,$Level,$Room,$Closed);
$stmt -> fetch();
$stmt -> close();
$conn -> close();

echo $Description .$Level .$Room .$Closed;

I cannot understand why I get no results I am getting the Connected Successfully message but no actual values are returned.


Solution

  • You need to execute() a prepared statement to make it do anything.

    $stmt = $conn->prepare('Select jmpPartShortDescription, ujmpLevel, ujmpRoom, jmpClosed from Inf_Jobs');
    //$stmt->bind_param('ss',$JobID,$ProjectID);
    
    $stmt->execute(); // <- this is what does the work
    
    $stmt -> bind_result($Description,$Level,$Room,$Closed);
    $stmt -> fetch();