Jump to content

Community

Error in your SQL syntax


Recommended Posts

Have error for MySQL select:

$select = \IPS\Db::i()->select( '*', 'news_artcms_news', array('categorynum LIKE ?','%main%'), 'news_artcms_news.num DESC', array( 0, 12 ) );
$results = \IPS\Db::i()->query($select);
Quote

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? ORDER BY news_artcms_news.num DESC LIMIT 0,12' at line 1

Where is my mistake?

I try to change problems code: 

array('categorynum LIKE ?','%main%')

to

array('categorynum = ?','main')

but error dont fixed....

categorynum is text field

Edited by Bazilisk
Link to comment
Share on other sites

Try using the like() method instead. Also, you do not need to pass your query to query() - simply convert $select to an array using the iterator_to_array() function.

$select = \IPS\Db::i()->select( '*', 'news_artcms_news', array( \IPS\Db::i()->like( 'categorynum', 'main', TRUE, TRUE ) ), 'news_artcms_news.num DESC', array( 0, 12 ) );
$results = iterator_to_array($select);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...

Important Information

We use technologies, such as cookies, to customise content and advertising, to provide social media features and to analyse traffic to the site. We also share information about your use of our site with our trusted social media, advertising and analytics partners. See more about cookies and our Privacy Policy