Mysqli::prepare + select ... where ... in + array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux