In model query –
public function get_articles_from_query($squery){
$query = DB::query(Database::SELECT, 'SELECT * FROM ieraksti WHERE virsraksts = "%:squery%" AND slug = "%:squery%" AND saturs = "%:squery%"')
->parameters(array(":squery" => $squery))->execute();
return $query;
}
Why this script is not working? I not have any errors, but blog articles not found.
Well, my first question is:
If not, the query will return no rows.
The use of the
%wildcards is forlike, not for=. If yoursqueryword isbanānsfor example, your query will only match rows where all three columns are exactly the literal%banāns%value, not a value containingbanānssomewhere within it.I think you want:
For your subsequent problem:
If that’s the case, you will have to change your query to something like:
In other words, move the attachment of the
%characters to the parameter specification, not the query itself. From your debug, the parameters are automatically having single quotes wrapped around them so, if you want to do anything inside those quotes, you have to do it before the wrapping.And you obviously don’t need the double quotes in this case because that wrapping is taking place.
And check that line with
"%$squery%"in it, I’m not sure it’s the right syntax. I’d say my PHP was a bit rusty but, to be honest, I’ve only ever used it for about seven minutes in my whole life 🙂What you’re aiming for is a string consisting of
%, the value of$squeryand another%.(a) Man tiešām patīk, kā Google Translate padara mani izskatās es zinu desmitiem dažādās valodās 🙂