user7042215
user7042215

Reputation:

PHP syntax differences from MySQL to SQL Server

I have been working on a Login/Register System, I had it all set up and working perfectly in MySQL, but I need to run it from SQL SERVER 2008, so I have changed the connection over and its all working apart from 1 bit, when the user click a verification link i the email it isn't verifying the user so I am thinking that some of the syntax doesn't work with PHP7 and SQL server.

This is the code:

$stmt = $user->runQuery("SELECT userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code LIMIT 1");
$stmt->execute(array(":uID"=>$id,":code"=>$code));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0){
some code...}
else{ error message...}

Its skipping the if statement and just giving me the error message from the else.

Is there something obviously wrong that i am not seeing?

Any help would be appreciated at this point!!

Thanks.

EDIT:

This is the code form the IF statement if it helps...

if($row['userStatus']==$statusN)
    {
        $stmt = $user->runQuery("UPDATE po_users SET userStatus=:status WHERE userID=:uID");
        $stmt->bindparam(":status",$statusY);
        $stmt->bindparam(":uID",$id);
        $stmt->execute();   

        $msg = "
               <div class='alert alert-success'>
               <button class='close' data-dismiss='alert'>&times;</button>
                  <strong>WoW !</strong>  Your Account is Now Activated : <a href='index.php'>Login here</a>
               </div>
               ";   
    }
    else
    {
        $msg = "
               <div class='alert alert-error'>
               <button class='close' data-dismiss='alert'>&times;</button>
                  <strong>sorry !</strong>  Your Account is allready Activated : <a href='index.php'>Login here</a>
               </div>
               ";
    }

Upvotes: 0

Views: 106

Answers (3)

Vitalii Strimbanu
Vitalii Strimbanu

Reputation: 477

So this error says that you try to call a member function on a boolean value

PHP Fatal error: Uncaught Error: Call to a member function sqlsrv_num_rows() on boolean

So instead of :

$stmt->execute(array(":uID"=>$id,":code"=>$code));
$row=$stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0){...

try this:

$result = $stmt->execute(array(":uID"=>$id,":code"=>$code));
if($result->rowCount() > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);

Hope this helps!

Upvotes: 0

Chandana Kumara
Chandana Kumara

Reputation: 2645

SQl Server does not have LIMIT. Limit use with mysql. Instead of Limit use top.

Refer:http://www.w3schools.com/sql/sql_top.asp

SELECT TOP 1 userID,userStatus FROM tbl_users WHERE userID=:uID AND tokenCode=:code

Upvotes: 1

Eric
Eric

Reputation: 3257

You need the TOP 1. You may be missing the 1.

SELECT TOP 1 userID, userStatus 
FROM tbl_users 
WHERE userID=:uID AND tokenCode=:code

Upvotes: 0

Related Questions