I have a problem when I get number of rows in SQL Server 2008 because my code works fine using MySQL but not in SQL Server.
$sql = "SELECT TOP 1 U.Id , U.Name, U.Profile, P.Name NameProfile
FROM sa_users U
INNER JOIN sa_profiles P ON P.Id = U.Profile
WHERE User = :user AND Pass = :pass";
$result = $this->dbConnect->prepare($sql) or die ($sql);
$result->bindParam(':user',$this->data['username'],PDO::PARAM_STR);
$result->bindParam(':pass',$this->data['password'],PDO::PARAM_STR);
if (!$result->execute()) {
return false;
}
$numrows = $result->rowCount();
$jsonLogin = array();
var_dump($numrows);
if($numrows > 0) {
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$jsonLogin = array(
'name' => $row['Name'],
'id' => $row['Id'],
'profile' => $row['Profile'],
'n_profile' => $row['NameProfile']
);
}
$jsonLogin['area'] = 'another';
return $jsonLogin;
} else {
return false;
}
var_dump($result->fetch()) in MySQL and SQL Server
array(8) {
["Id"]=>
string(1) "1"
[0]=>
string(1) "1"
["Nombre"]=>
string(13) "Administrador"
[1]=>
string(13) "Administrador"
["Perfil"]=>
string(1) "1"
[2]=>
string(1) "1"
["NomPerfil"]=>
string(13) "Administrador"
[3]=>
string(13) "Administrador"
}
var_dump($numrows) in SQL Server
int(-1)
var_dump($numrows) in MySQL
int(1)
Regards.