3

私は2つのストアプロシージャを持ってnいます。一致するすべてのレコードを選択する最初のものにレコードをページングする必要がありました(たとえば、次のすべてのレコードを選択します)。

CREATE PROCEDURE `trans_all`(IN varphone VARCHAR(15))
BEGIN
  Select
  loans.amt,
  loans.date,
  loans.pay_period,
  borrower.phone As borrower_phone,
  borrower.name As borrower_name,
  lender.phone As lender_phone,
  lender.name As lender_name,
From
  loans Left Join
  users borrower On borrower.id = loans.borrower_id Left Join
  users lender On lender.id = loans.lender_id
Where
   (lender.phone = varphone) or (borrower.phone = varphone);
END

次に、phpでカウントを取得します;このように

$result = $mysqli->query(sprintf("call trans_all('%s')",$phone));
$num_recs = $result->num_rows; 

次に、これを行うために正確なレコードを選択する必要がありました

$result = $mysqli->query(sprintf("call trans_history('%s','%s','%s')",$phone,$start,$limit));

$row = $result->fetch_assoc(); // this like gives the error Commands out of sync; you can't run this command now

2 番目のストアド プロシージャは

CREATE PROCEDURE `trans_history`(IN varphone VARCHAR(15), IN page INT, IN items INT)
BEGIN
  Select
  loans.amt,
  loans.date,
  loans.pay_period,
  borrower.phone As borrower_phone,
  borrower.name As borrower_name,
  lender.phone As lender_phone,
  lender.name As lender_name,
From
  loans Left Join
  users borrower On borrower.id = loans.borrower_id Left Join
  users lender On lender.id = loans.lender_id
Where
   (lender.phone = varphone) or (borrower.phone = varphone)  LIMIT page , items;
END

このエラーの原因は何ですか?

4

1 に答える 1

6

SP は、ステータスを含む 2 番目の結果セットを返します。next_result()後続のクエリを行う前に使用する必要があります。

$result = $mysqli->query(sprintf("call trans_all('%s')",$phone));
$num_recs = $result->num_rows; 
$result->close();
$mysqli->next_result(); // <- you need this before you make another query

//Then make call second SP
$result = $mysqli->query(sprintf("call trans_history('%s','%s','%s')",$phone,$start,$limit));
$row = $result->fetch_assoc();
$result->close();
$mysqli->next_result();
于 2013-05-22T04:02:18.773 に答える