php - PDO rowCount() works on MySQL but not in SQL Server 2008 R2 -


i have problem when number of rows in sql server 2008 because code works fine using mysql not in sql server.

$sql = "select top 1 u.id , u.name, u.profile,  p.name nameprofile         sa_users u         inner join sa_profiles p on p.id = u.profile         user = :user  , 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 , 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.

just quoting manual:

if last sql statement executed associated pdostatement select statement, databases may return number of rows returned statement. however, this behaviour not guaranteed databases , should not relied on portable applications.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -