Hey there

I have been toying around with the following code for a few days:

<?php
//Gets the tokens defined in the array $tokensToGet, with the language defined by $languageId
public static function GetTokens($tokensToGet, $languageId)
{
   $query =
   @"SELECT
       Name,
       Value
   FROM
       InterfaceLanguageTokens
   WHERE
       Name IN (?) AND
       InterfaceLanguageId = ?";

   $tokens = array();

   $mysqli = Database::Connect();
   if($stmt = $mysqli->prepare($query))
   {
       $stmt->bind_param('si', $tokensToGet, $language);
       $stmt->Execute();
       $stmt->Bind_result($name, $value);
       while($stmt->fetch())
       {
            $tokens [] = array("name" => $name, "value" => $value);
       }

       $stmt->Close();
   }

   $mysqli->close();
   return $tokens;
}
?>

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
System Developer

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to