这是我的错误。
警告:odbc_exec():SQL错误:[Microsoft] [ODBC SQL Server驱动程序] [SQL Server] Sintaxis不正确的cerca de' 123'。,SQL状态37000 in位于 19 的 C:\ xampp \ htdocs \ Estadias \ api \ MODELS \ connection_sql_server.php 中的SQLExecDirect 错误[Microsoft] [ODBC SQL Server驱动程序] [SQL Server] Sintaxis不正确的cerca de' 123'。
查询:
select todos.matricula,u.constrasenia, todos.nombres,todos.paterno,t.id ,t.description
from usuarios u join typeofuser t on u.tipo = t.id
join (select matricula,nombres, paterno from Alumnos union select id as
id, numbres, paterno from tutores union select id as id, nombre, paterno
from asesor_empresarial) todos on todos.matricula = u.id where u.id =
'12312' and u.constrasenia = '123';
这是我的代码。
$user= $_POST['usr_id'];
$pswd=$_POST['usr_psw'];
if (isset($user) && isset($pswd))
{
$connection = new SqlServerConnection();
try
{
$query = sprintf('select todos.matricula,u.constrasenia,
todos.nombres,todos.paterno,t.id ,t.description from usuarios u
join typeofuser t on u.tipo = t.id join (select matricula,nombres,
paterno from Alumnos union select id as id, numbres, paterno
from tutores union select id as id, nombre, paterno
from asesor_empresarial) todos on todos.matricula = u.id where u.id =
\''.$user.'\' and u.constrasenia = \''.$pswd."';");
echo $query;
$data=$connection->execute_query($query);
odbc_result($data, 'matricula');
odbc_result($data, 'constrasenia');
odbc_result($data, 'nombres');
odbc_result($data, 'paterno');
odbc_result($data, 'id');
odbc_result($data, 'description');
if (odbc_result($data, 'matricula')=='' && odbc_result($data, 'constrasenia')=='') {
echo $result='{"status" : 1 , "Descrition" : "User Not Found" }';
die;
}
$u = new User(odbc_result($data, 'id'),odbc_result($data, 'constrasenia'));
echo '
{ "status" : "0" ,
"User":
{
"userID" : "'.$u->get_id().'",
"nombre" : "'.$nombre.'",
"paterno" : "'.$paterno.'",
"imagen" : "'.$img.'",
"UserType" :
{
"ID" : "'.$u->get_user_type()->get_id_type().'",
"Description" : "'.$u->get_user_type()->get_description().'"
},
"token" : "'.generate_token($user).'"
}
}';
}
finally
{
$connection->close();
}