Answer the question
In order to leave comments, you need to log in
Why is only the first match returned when using the LIKE operator in mysql?
Actually, the essence is this: there is a sql query, there is a database.
The request itself looks like this:
SELECT `service` FROM `service_synonyms` WHERE `synonym` LIKE '%$query%'
$sql = "SELECT `service` FROM `service_synonyms` WHERE `synonym` LIKE '%$query%' ";
$result = $this->_dbconn->query($sql)->fetch_array(MYSQLI_ASSOC);
Answer the question
In order to leave comments, you need to log in
Because there are two functions: fetch and fetchAll. After the first one, you need to move over the cursor using the next function. The second one will return all rows from the cursor in one call.
The bottom line, in fact , is that
First: porting his code from the "procedural model" to the "object-oriented" author managed not to notice the cycle that was in the first, but disappeared in the second. But the OOP PHP model was to blame.
The second and most important thing: porting his old shit code with mysql_*, the author mastered only adding the letter i and arrows, leaving everything else as it is. Having received in the end exactly the same govnokod as before.
For reference:
The point of migrating from mysql to mysqli is not to add a dot wand. It's about using prepared expressions .
The point of OOP is not to write sticks with angle brackets. And that the object encapsulates within itself all the data processing work, returning the desired result immediately. As a result, the code that actually uses OOP should look something like this:
$sql = "SELECT `service` FROM `service_synonyms` WHERE `synonym` LIKE ?";
$result = $this->_dbconn->getAll($sql, "%$query%");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question