Laravel query returns question mark instead of variable value

Kevin Kromjong

When I click on a button, an AJAX-call is being made to my self written API. When the button is clicked, the Javascript file retrieves two data-attributes from the clicked object and sends it along with the URL. The two variables are used in the where clause of the yet to be executed SQL-statement.

When the call is being made, the PHP-script that handles the API requests receives the two variables via Input::get('data-attribute-one')) and Input::get('data-attribute-two')). When I output these two attributes, the correct values are displaying.

However, when I put the variables into the where-clause of my query, like so:

$fans = Sensor::where('fan_number', '=', $dataAttributeOne)->where('created_at', '>=', $this->now->subHours(6))->get();

no results are returned. So I replaced ->get() with ->toSql() to check the query and it presented me with this strange line of code:

Object {fans: "select * from "myawesomedatabasetable" where "fan_number" = ? and "created_at" >= ?"}

$dataAttributeOne is the retrieved data-atribute and $this->now->subHours(6) is the current time minus 6 hours. When I output this, it is in the same format as the created_at value in the database and when I hardcode it into an SQL-statement in Phpmyadmin, the query executes like a charm. So no problems there.

So my question is: why are the variables turning into question marks when the query executes and how do I solve this?

Thanks in advance!

Alexey Mezenin

That's just how toSql() works. This method is used for debugging.

https://scotch.io/tutorials/debugging-queries-in-laravel

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

include log4j properties file in hibernate to show query with value instead of question mark

Laravel query builder not replacing question mark

Google Oauth-2.0 returns url with hash instead of question mark

jOOQ addConditions: in SQL question mark appears instead of the value

Getting the value of a pound sign (£) in JSON returns a question mark (?)

Question mark Typescript variable

question mark in the url with laravel

Question mark in laravel toSQL()

Question mark in XML as value

Question mark instead of RTL field

URL: semicolon instead of question mark

Laravel query returns builder instead of collection

Sql: Query returns column name instead of Value

PDO query returns "Array" instead of value

Swift variable decorations with "?" (question mark) and "!" (exclamation mark)

Indirect expansion returns variable name instead of value

Prolog returns variable name instead of value

Android question mark after variable

Why do i get question mark in console instead of a double value / NaN and what does it mean?

Why is the output a question mark in a box instead of a number?

Question mark icon instead of wifi icon

parameters as part of url instead of after question mark

Mariadb query variable with null value returns nothing

Arduino GSM module returns "?"question mark character

Lua unusual variable name (question mark variable)

Email in laravel shows variable instead of the value

Laravel Query builder returns a row from join instead of multiples row

Laravel boolean returns "1"/"0" instead of true/false in query

Does Laravel's toSql() method mask ids? (column value being replaced by question mark)