1

Is there any way to do something like this:

SELECT * FROM table WHERE p1=1 AND p2=2 AND ( p3 like %string1% OR p3 like %string3% )

In Zend Framework 1 by Zend_Db_Select or something else ?

2 Answers 2

1

Not sure about how you would go about doing such complex nested query using Zend_Db_Select but you can write can consider writing query manually as follows -

$sql = 'SELECT * FROM table WHERE p1 = ? AND p2 = ? AND (p3 LIKE ? OR p3 LIKE ?)';

$db->fetchAll($sql, [$p1, $p2, "%{$p3}%", "%{$p4}%"]);
Sign up to request clarification or add additional context in comments.

Comments

1

You should rather use Zend_Db_Statement, which gives flexible options for fetching result sets. You can use:

      $stmt = $db->query(
              'SELECT * FROM table WHERE p1 = ? AND p2 = ? AND (p3 LIKE ? OR p3 LIKE ?',
               array('1', '2', '%string1%', '%string3%')
              );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.