Use a variable in a setWhereClause()

I have tried to use a variable in a setWhereClause in PHP , but i get an “invalid where clause”

for example:

$query2->setWhereClause(‘precio_SORT2 > " $precioMin"’);

It means the where clause your code produces is invalid. Have you checked what the where clause ends up being?

It’s wrong to write “$variable” in a where clause ?

the messagge i get :Fatal error: Uncaught exception ‘backendless\exception\BackendlessException’ with message 'Backendless API return error: Invalid where clause at position 6: no viable alternative at input ‘uso="$tipoB"’ Error code:1017

a where clause must be a string which will be evaluated by the server. I am sure you can use variables in it, but the FINAL result must be in the syntax understood by the server.

Thanks, but i don’t know what is wrong in my code .

for example if my variable is a string i have to use double quote or single quote?

if a variable $var contains a numeric value, this is how you can concatenate them in PHP:

$query2->setWhereClause('precio_SORT2 > " . strval( $var ) );

if the variable contains a string value, the value (not the variable) must be surrounded by single quotes:

$query2->setWhereClause('precio_SORT2 > ‘" . $var . "’" );

Thanks Mark it works ¡¡¡¡¡¡¡¡¡¡

Hi @Mayank_Jain,

could you please open a new topic with this issue (looks like it does not related to the current topic about PHP), and provide us with more details about your issue? Some examples of code, screenshots, anything that can help us identify the problem would be beneficial.

Regards,
Stanislaw