2017-09-07 4 views
-2

스피이 오류가왜 iam이 error_log 파일의 bind_result와 관련된 오류를 받고 어떻게 수정해야합니까?

[07 - 9 월 - 2017 세계 협정시 11시 48분 47초] PHP 경고 : mysqli_stmt :: bind_result() : 바인드 변수의 번호의 필드의 수와 일치하지 않습니다 이 코드는 경고없이 당신에게 해답을 줄 것이다

$stmt = $con->prepare("SELECT * FROM table where Id =?"); 
$stmt->bind_param("s", $_POST['Id']); 
$stmt->execute(); 
$result = $stmt-> bind_result($Id); 
$numRows = $result->num_rows; 
if($numRows > 0) { 
if($row = $result->fetch_assoc()) 
{ 
$Taxname=$row['TaxName']; 
$Tid=$row['Id']; 
}} 
+0

'$ Id'에서 얻는 가치는 무엇입니까? – Gunaseelan

+0

@Gunaseelan sir .i는 bind_result에서 변수가 무엇인지 알아야합니까? 가치는 데이터베이스에서 오는 것입니까? – krish

+0

테이블 이름'table'에서 몇 개의 열과 모든 열 값을 가져 왔습니까? – Gunaseelan

답변

0

을 위해 준비된 문에 변수를 바인드합니다. * 대신 데이터베이스에서 실제로 원하는 데이터를 선택해야합니다. 테이블 table가 열 Id,TaxName이있는 경우
예를 들어, 당신은과 같이 실행합니다 :

<?php 
$sqlData = array(); 
$stmt = $con->prepare("SELECT Id,TaxName FROM table where Id =?"); 
$stmt->bind_param("i", $_POST['Id']); //id is an integer? this should be i instead of s 
$stmt->execute(); 
$stmt->store_result(); //store the result, you missed this 
$stmt-> bind_result($Id,$TaxName); //bind_result grabs the results and stores in a variable 
$numRows = $stmt->num_rows; //see the correction I made here 
if($numRows >0){ 
     while ($stmt->fetch()) { //propper way of looping thru the result set 
      $sqlData [] = array($Id,$TaxName); 
      //assoc array would look like: 
      //$sqlData [] = array("Id" =>$Id,"TaxName" => $TaxName); 
     } 
} 
$stmt->close(); //close the connection 
?> 

그런 다음 당신은 당신이 mysqli 쿼리를 완료 한 후 사용할 수있는 결과의 배열을 가질 것이다. 희망 사항을 통해이 내용을 조금 더 이해할 수 있습니다.

0
$stmt = $con->prepare("SELECT Id,TaxName FROM table where Id =?"); 
$stmt->bind_param("s", $_POST['Id']); 
$stmt->execute(); 
$result = $stmt-> bind_result($Id,$TaxName); 
$stmt->store_result(); 
$numRows = $stmt->num_rows; 
if($numRows > 0) { 

    while($result->fetch_assoc()) 
    { 
    $newid = $Id; 
    $newtaxname= $TaxName; 
    } 
    print_r($newid)."<br>"; 
    print_r($newtaxname); 
} 

문 준비했다.

참조 : http://php.net/manual/en/mysqli-stmt.bind-result.php

mysqli_stmt :: bind_result은 - 결과 저장 당신은 당신의 쿼리를 변경해야

+0

'$ result = $ stmt-> bind_result ($ Id, $ TaxName);'문서에서'bind_result'는'TRUE' 또는'FALSE'를 반환합니다. '$ numRows'는 항상 0을 반환 할 것이기 때문에 오류/경고를받지 못할 것입니다. – IsThisJavascript

+0

@ WillParky93'$ result-> num_rows' 대신'$ stmt-> num_rows'로 응답을 업데이트했습니다. – Gunaseelan

+0

'$ stmt-> num_rows; 앞에'$ stmt-> store_result();'를 포함하도록 답을 편집하십시오'prepare'를'query'가 아니고'num_rows'를 준비하는 것은 그렇게 좋아하지 않습니다 ! 이 경우, num_rows는 0 또는 잘못된 숫자를 반환합니다. – IsThisJavascript