Mysqli::prepare + select ... where ... in + array
- From: hanshenp@xxxxxxxxx ("Hans Henrik Petersen")
- Date: Tue, 26 Aug 2008 10:35:15 +0200
I have been toying around with the following code for a few days:
//Gets the tokens defined in the array $tokensToGet, with the language
defined by $languageId
public static function GetTokens($tokensToGet, $languageId)
Name IN (?) AND
InterfaceLanguageId = ?";
$tokens = array();
$mysqli = Database::Connect();
if($stmt = $mysqli->prepare($query))
$stmt->bind_param('si', $tokensToGet, $language);
$tokens  = array("name" => $name, "value" => $value);
The problem is this: WHERE NAME IN (?) – I would consider it logical that
the prepare statement can take a type of array – in this case an array of
strings that I then with the bind_param statement, with the type "s".
Unfortunately this doesn't work.
To get around this problem I have to go around the problem and use string
gymnastics – something like this: $tokensToGetString = "'" . implode("','",
$tokensToGet) . "'" and add that instead of the (?).
I hope you can help me out in this matter. Thank you in advance.
Hans Henrik Petersen
- Prev by Date: Large/unreliable file uploading over HTTP
- Next by Date: Re: [PHP] multiple question form creation
- Previous by thread: Large/unreliable file uploading over HTTP
- Next by thread: Re: [PHP] multiple question form creation