問題描述
這是我第一次使用mysqli.它似乎在 mysqli_num_rows() 中的括號之間尋找結果集的名稱.然而,當我嘗試 $stmt、$conn 和什么都沒有時,我得到了同樣的錯誤.令人沮喪!下面最后一行中的 $WHAT 是什么?
This is my first experience with mysqli. It seems to be looking for the name of a result set in between the parentheses in mysqli_num_rows(). Yet when I tried $stmt, $conn, and nothing, I got the same error. Frustrating! What goes where $WHAT is in the last line below?
或者我嘗試的方式不對.我想要做的就是檢查是否返回了結果.我真的不需要行數.我應該只做一個帶有錯誤消息的 else 語句嗎?這是最好的方法嗎?是否有一種編寫函數來連接和接受查詢及其參數的好方法?我為 mysql 寫了一個,但這太不同了!我不期待重寫幾十個查詢!
Or maybe I'm trying the wrong tack. All I want to do is check that a result was returned. I don't really need the number of rows. Should I just do an else statement with an error message? Is that the best way to do it? And is there a good way to write a function to connect and accept the query and it's parameters? I wrote one for mysql but this is so different! I'm not looking forward to rewriting dozens of queries!
$conn = mysqli_connect($host, $user, $pwd, $db,$port=$port_nbr);
if ($mysqli_connect_errno) {
printf("Connect failed: %s
",
mysqli_connect_error());
exit;
}
if($stmt=$conn->prepare("SELECT id, name, status, type FROM organization")) {
$stmt->execute();
$stmt->bind_result($org_id, $orgname, $orgstatus, $orgtype);
$num=mysqli_num_rows($WHAT);
}
推薦答案
當您只想要面向對象時,您正在結合面向過程和面向對象的方法.改變
You're combining procedural and object oriented approaches, when you only want object oriented. Change
$num=mysqli_num_rows($WHAT);
到
$num = $stmt->num_rows();
這篇關于mysqli_num_rows() 期望參數 1 是 mysqli_result,對象的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!