本文介紹了如何在mysqli中做mysql_fetch_assoc?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何在 mysqli prepare 語句中執行以下操作?
How can I do the following in mysqli prepare statement?
$result = mysql_query($sql);
$data = mysql_fetch_assoc($result);
return $data:
推薦答案
在某處創建到 mysql 的連接后,這很簡單:
That's pretty simple after you've created the connection to mysql somewhere:
<?php
// create the connection to mysql.
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
?>
當你需要做查詢或做其他事情時引用 mysqli 對象.
The refer to the mysqli object when you need to do a query or do something else.
<?php
// get the result object.
$result = $mysqli->query($sql);
// fetch the result row.
$data = $result->fetch_assoc();
return $data;
?>
然后在某個時候(如果你有一個類,你可以寫一個析構函數)如果你不再需要它,你應該關閉與 mysql 的連接.
Then at some point (if you have a class, you can write a destructor) you should close the connection to mysql if you won't need it anymore.
<?php
$mysqli->kill($mysqli->thread_id);
$mysqli->close();
?>
你可以用你擁有的結果對象做更多的事情.因此,請在此處閱讀有關 MySQLi_Result
的更多信息:
You can do much more with the result object you have.
So read more about the MySQLi_Result
here:
- http://www.php.net/manual/en/class.mysqli-result.php
這篇關于如何在mysqli中做mysql_fetch_assoc?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!