I am doing an execution from php like this:
$query1 = odbc_prepare($conn, "SELECT User FROM sqlsv2008r2.dbo.tabla WHERE email = ? ");
$result_1 = odbc_execute($query1, array($email));
if(odbc_num_rows($result_1)>0)
{
die("<center><h2><font color='red'>El Correo</font> <font color=#EEEA0B'>$email</font><font color='red'> NO esta Disponible</font></h2></center>");
}
I get this error:
Warning: odbc_execute() [function.odbc-execute]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]The data types varchar(max) and text are incompatible in the equal to operator., SQL state 37000 in SQLExecute in C:\xampp\htdocs\gg\ar_.php on line 3
How can I solve that? I use SQL server 2008 r2
The error is due to a (fully justified) limitation of the driver you are using, for more details check this knowledgebase post and also this post .
In the Resolution section of the first link it says the following:
That is, ODBC limits how large columns can be used in type criteria
WHERE laColumna = elValor
for performance reasons (you generally don't declare a huge column to use for filtering or sorting data).When your column
email
is declared a type,varchar(max)
it will have a size of 8,000 characters. Will there be an email address with 8,000 characters?Solution
Declare your column
email
with a smaller size. According to this answer the standard size for columns with email addresses is usuallyvarchar(320)
.Another solution (mediocre for this case) would be to change the
WHERE
to aLIKE
.Another solution (also mediocre in this case) is the one indicated in the second above, which consists of moving to ODBC version 10.
Both are mediocre because even if it works, the most serious thing here is a design error when allocating 8,000 characters to a column whose data will never, ever reach that length.