Hi, I am using the php mysqli extension with prepared statements, but on one query it is not creating the query object.
Here is the code:
$sqlq = "SELECT id,name FROM productcategories JOIN products ON productcategories.productid = products.id WHERE categoryid=?";
if($allsubcats)
{
foreach($allsubcats as $key => $data)
{
$sqlq .= " OR categoryid=?";
}
}
echo $sqlq;
if($query = $this->mysqli->connection->prepare($sqlq))
{
$query->bind_param("i", $cat);
if($allsubcats)
{
foreach($allsubcats as $key => $data)
{
$query->bind_param("i", $data[0]);
}
}
$query->execute();
$query->bind_result($id,$name);
$query->store_result();
if($query->num_rows > 0)
{
while($row = $query->fetch())
{
$allprods["id"] = $id;
$allprods["name"] = $name;
}
}
$query->close();
}
The problem:
The line "if($query = $this->mysqli->connection->prepare($sqlq))"
The if() is returning false, and therefore not creating the $query object, and not executing any of the code inside the if.
The "echo $sqlq;" returns
"SELECT id,name FROM productcategories JOIN products ON productcategories.productid = products.id WHERE categoryid=? OR categoryid=? OR categoryid=? OR categoryid=? OR categoryid=? OR categoryid=?"
Which I don't see anything wrong with.
Any help would be greatly appreciated,
Thanks, Nico