2016-05-28 55 views
1

在這個num_rows的組合中,bind_param en fetch(_assoc)。查詢符合num_rows,bind_param和fetch_assoc

我在$ salt = $ saltuitkomst ['salt']中沒有得到任何結果;

$用戶= 195

$行是給數1作爲結果

無錯誤消息

$saltqry = "SELECT 
        salt, 
        mw_gegevens_groep 
      FROM 
        mw_gegevens 
      WHERE 
        mw_gegevens_persnr = ? 
      "; 
      if(!$statement = $connection->prepare($saltqry)) 
      { 
      echo "Query error:.". $connection->error(); 
      } else { 
       if(!$statement->bind_param('i', $user)){ 
       echo "bind param did not work"; 
       }else{ 
       $statement->execute(); 
       $statement->store_result(); 
       $rows = $statement->num_rows; 
       $saltuitkomst = $statement->fetch(); 
       } 
      } 
     if($rows == 0) { 
       $salt=''; 
     } else { 
       $salt = $saltuitkomst['salt']; 
       echo '-'.$salt.'-'; 
     } 
+0

也許'salt'是空 – RiggsFolly

+0

無鹽是somethnig如:/ 0Es0ETaUwL2PXnNND7Af – Coolen

回答

2
$saltqry = "SELECT 
        salt, 
        mw_gegevens_groep 
      FROM 
        mw_gegevens 
      WHERE 
        mw_gegevens_persnr = ? 
      "; 
      if(!$statement = $connection->prepare($saltqry)) 
      { 
      echo "Query error:.". $connection->error(); 
      } else { 
       if(!$statement->bind_param('i', $user)){ 
       echo "bind param did not work"; 
       }else{ 
       $statement->execute(); 
       $statement->store_result(); 
       $statement->bind_result($salt, $group); 
       $saltuitkomst = $statement->fetch(); 
       if($saltuitkomst) { 
        echo '-'.$salt.'-'; 
       } else { 
        $salt=''; 
       } 
       $statement->close(); 
       } 
     } 
+0

@Coolen謝謝,在查詢中有第二個參數... –

+0

歡迎您,這是唯一的解決方案嗎?我有另一個qry,但它使用*,所以bid_result將無法正常工作。 – Coolen

+1

只是以逗號分隔所有表格的字段作爲參數。這意味着如果表有3個字段的ID,名稱,電子郵件做'bind_result($ id,$ name,$ email);'在你的查詢當然你會使用'select id,name,email from table' –