Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In example missing - think passing an array is broken? #1

Open
intellix opened this issue Mar 9, 2012 · 0 comments
Open

In example missing - think passing an array is broken? #1

intellix opened this issue Mar 9, 2012 · 0 comments

Comments

@intellix
Copy link

intellix commented Mar 9, 2012

Hey, sorry if this is the wrong place to put this. I've been trying to use IN but I'm thinking that it's not working correctly.

Code:
$idList = array('1', '2', '3', '4', '5');
// Get adapter set before
$adapter = $this->getAdapter();

    // Grab squares between
    $select = new Select;
    $select
        ->from($this->getTableName())
        ->join(
            'map_types', 
            'map_types.map_id = map.id',
            array('map_types.type')
        )
        ->where->in('map.id', $idList);

    $statement = $adapter->createStatement();
    $select->prepareStatement($adapter, $statement);

    $resultSet = new ResultSet();
    $resultSet->setDataSource($statement->execute());

    return $resultSet;

I'm thinking that I'm passing in the list of ID's within the IN parameter correctly. The next piece of dump should illustrate:

["sql":protected] => string(141) "SELECT *, map_types.map_types.type FROM map INNER JOIN map_types ON map_types.map_id = map.id WHERE map.id IN (:where1)"
["isQuery":protected] => NULL
["parameterContainer":protected] => object(Zend\Db\Adapter\ParameterContainer)#479 (2) {
["data":protected] => array(5) {
["where1"] => string(1) "1"
["where2"] => string(1) "2"
["where3"] => string(1) "3"
["where4"] => string(1) "4"
["where5"] => string(1) "5"
}
["errata":protected] => array(5) {
["where1"] => NULL
["where2"] => NULL
["where3"] => NULL
["where4"] => NULL
["where5"] => NULL
}
}

I tried to pass in the imploded array but then it says that it requires an array. Went through the code and I guess this is the bit that only lets it have the first value:

Zend\Db\Sql\Where->prepareStatement()

$wherePart .= vsprintf($part[0], $values);

If I'm doing it wrong then it would be great to see an example of its correct usage :)

Thanks and thanks for making it easier to debug the SQL output!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant