I'm trying to do a query to retrieve all users using eloquent ORM laravel5 PDO ODBC connection and when tray to do this
$email = "myemail@domain.com";
$data = Users::where('email',$email)->get();
I get this error
"SQLSTATE[42000]: Syntax error or access violation: 402 [FreeTDS][SQL Server]The data types varchar and text are incompatible in the equal to operator. (SQLExecute[402] at /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_lang_php/php56-odbc/work/php-5.6.19/ext/pdo_odbc/odbc_stmt.c:254) (SQL: select * from \"Users\" where \"email\" = 'myemail@domain.com')"
as you see I'm using FreeTDS to connect with SQL Server, I don't know if this driver needs an aditional configuration or I have to modify laravel core.
In this error the main problem is \"Users\" and \"email\"
backslash and quotation marks around Users
and email
. How can I remove this quotation marks and why laravel is doing this.
however if I try this
$sql = "SELECT * FROM $this->table WHERE email = 'myemail@domain.com'";
$return = DB::select(DB::raw($sql));
it works perfectly, but I think this isn't the better way to build queries in laravel.
FYI
I'm using laravel 5 on Mac OS X EL Capitan, MAMP Server, php 5.6.10, pdo-odbc
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire