問題描述
我正在查看我的代碼并讀到它被推薦使用 mysqli_free_result
當你的結果對象不再需要時.但是在看到每個查詢在整個腳本中反復輸出到 $result
變量后,我想知道 mysqli_free_result
是否真的有必要.似乎每次運行查詢時 $result
變量已經被清除并設置為新結果.只是好奇是否有人對此有任何意見.
I was looking through my code and read that it was recommened to use mysqli_free_result
when your result object is not needed anymore. But after seeing that each query is outputed to the $result
variable repeatedly throughout the script, I am wondering if mysqli_free_result
would really be necessary. Seems like each time a query is ran the $result
variable is already being wiped clean and set to a new result. Just curious if anyone has any input on this.
推薦答案
這從來都不是絕對必要的,但密切關注您正在使用的資源并知道何時不再需要它們是一種很好的做法.
It’s never strictly necessary, but it's good practice to keep an eye on resources you’re using and know when you don't need them anymore.
添加那行額外的代碼非常簡單,所以每次你完成結果集時我都會這樣做.它還有一個額外的好處,即在您完成資源后讓閱讀您的代碼的人清楚.
It’s pretty minimal effort to drop in that extra line of code, so I would just do it every time you're finished with a result set. It has the added bonus of making it clear to someone reading your code when you’ve finished with a resource.
這篇關于mysqli_free_result 有必要嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!