Edit: To clarify, I'm using PDO to MySQL database
Ok I have a slight problem with a query. I've tried googling and 'stackoverflowing', to no avail. I'm trying to select all records from a table called download store, where the ownerid = '1'
//Partial code
$sql="SELECT * FROM boughtdownloads WHERE ownerid=:userid";
$prep=$GlobalDB->prepare($sql);
$prep->bindParam(':userid',$userid,PDO::PARAM_INT);
$prep->execute();
if($prep->rowCount()=='0')
{
return 'Error with get owned IDS';
}
else
{
foreach($prep->fetchAll()as $res)
{
$owned[]=$res['fileid'];
}
$owned=implode(",",$owned);
return $owned;
}
That works as expected, returning 1,2
$OwnedIDS=$this->GetOwnedIDS($userid); // The same code as above ^
//This query doesn't work, even with the following:
//$OwnedIDS="1,2"; //Which is what's expected, and returned, from the above
$sql="SELECT * FROM downloadstore WHERE fileid IN (:owned)";
$prep=$GlobalDB->prepare($sql);
$prep->bindParam(':owned',$OwnedIDS);
$prep->execute();
if($prep->rowCount()=="0")
{
return 'Error with remaining disk space';
}
else
{
echo $prep->rowCount();
}
This only returns 1 record, despite two records being in the downloadstore table
$GlobalDB
= pdo connection string (which works)
$userid = $_SESSION
, which equals "1"
[Download Store screenshot]
[BoughtItems screenshot]
As you can see, there are 2 records in each table, with valid fileid's.
But only 1 record is being pulled when querying the download store with the IN clause.
Could someone help me out please? It's probably something stupidly simple I'm overlooking, but I've triple checked and I'm sure there's nothing wrong (although clearly there is) with my query or the table(s).
Thanks, Rob