BomAle Posted August 15, 2017 Posted August 15, 2017 <?php require_once './init.php'; $where = array ( 'pid IN(57,58)', 'poll_closed=1' ); $select = \IPS\Db::i()->select( 'COUNT(*) as cnt', 'core_polls', $where ); var_dump($select->query);exit; it print: D:\Programmi\Ampps\www\ips4\test.php:10:string 'SELECT COUNT(*) as cnt FROM `core_polls` WHERE pid IN(57,58)' (length=60) where is poll_closed go? Can anyone test this for 4.2.2 or lastest? @bfarber
Stuart Silvester Posted August 15, 2017 Posted August 15, 2017 Your where is structured incorrectly, the second index of the array is used for binds (prepared statements), not another where clause. See the comments on \IPS\Db::compileWhereClause(): /** * Compile WHERE clause * * @code // Single clause "foo IS NOT NULL" // Single clause with bound values (always bind values to ensure they are properly escaped) array( 'foo=?', 'fooValue' ) array( 'foo=? OR bar=?', 'fooValue', 'barValue' ) // Multiple clauses (will be joined with AND) with bound values array( array( 'foo=?, 'fooValue' ), array( 'bar=?', 'barValue' ) )
Adriano Faria Posted August 15, 2017 Posted August 15, 2017 I would do: $where[] = array( \IPS\Db::i()->in( 'pid', array( '57', '58' ) ) ); $where[] = array( 'poll_closed=1' ); Returns: Quote C:\wamp64\www\test.php:8:string 'SELECT COUNT(*) as cnt FROM `core_polls` WHERE ( pid IN('57','58') ) AND poll_closed=1' (length=86)
BomAle Posted August 16, 2017 Author Posted August 16, 2017 Thanks for all, I have missed compileWhereClause instructions, therefore I have changed: [[\IPS\Db::i()->in( \IPS\advpolls\Poll::$databasePrefix . \IPS\advpolls\Poll::$databaseColumnMap['container'], iterator_to_array( \IPS\Db::i()->select( \IPS\advpolls\Category::$databasePrefix . \IPS\advpolls\Category::$databaseColumnId, \IPS\advpolls\Category::$databaseTable ) ) )]] into \IPS\advpolls\Table constructor (temporary fix, avoiding uncategorized polls)
Recommended Posts
Archived
This topic is now archived and is closed to further replies.