1

I want to make a consult to the MSSQLSERVER with a SELECT STATEMENT but the sqlsrv_query is returning FALSE to me.

I already tested the query and its working fine, am I passing the parameters correctly?

Here is my code:

    if($conn === false)
    {
        die(print_r(sqlsrv_errors()));
    }


     try
        {
$email = "[email protected]";
            $sql = "select Usuario.Email, Usuario.Senha FROM Usuario WHERE Usuario.Email = (?)";

            $params = array($email);

        $stmt = sqlsrv_query( $conn, $sql, $params);

if($stmt != False)
        {
            if($row = sqlsrv_fetch_Array($stmt))
            {
                $email_Con = $row['Email'];
                $psw_Con = $row['Senha'];
            }
            else
            {
                echo "alguma coisa";
            }


        }
else
{
   echo "It always enters here!";
}
2
  • What is the result of sqlsrv_errors()? Commented Jan 28, 2015 at 18:15
  • "SQLSTATE: IMSSP<br />code: -14<br />message: An invalid parameter was passed to sqlsrv_query.<br /> Commented Jan 28, 2015 at 18:18

1 Answer 1

1

Two possible problems.

The first is the format of your query. You are using:

select Usuario.Email, Usuario.Senha FROM Usuario WHERE Usuario.Email = (?)

Where I think you should be doing:

select Usuario.Email, Usuario.Senha FROM Usuario WHERE Usuario.Email = ?

The second is that the An invalid parameter was passed to sqlsrv_query() message is common when the connection is not correct (Reference). So double check that your connection is a valid resource.

Sign up to request clarification or add additional context in comments.

4 Comments

Done that... didn't work and received the same error
even if I try $sql = "select Usuario.Email, Usuario.Senha FROM Usuario WHERE Usuario.Email = '[email protected]'"; // $params = array($email); $stmt = sqlsrv_query( $conn, $sql); I get the same error.
Its not the connection because i have $server = "[SERVER]"; $user = "[USER]"; $pwd = "PSW"; $db = "DB"; if($conn === false) { die(print_r(sqlsrv_errors())); }
I was wrong, my connection string was quite wrong. Thank you for giving me these options... I tough the error was the parameters of the QUERY, not the SQLSRV_QUERY parameters...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.