Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted August 15, 20177 yr <?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
August 15, 20177 yr 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' ) )
August 15, 20177 yr 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)
August 16, 20177 yr Author 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)
Archived
This topic is now archived and is closed to further replies.