-1
我來自一個C#
背景,你可以做以下從任何方法的類靜態變量在PHP類
public class Test
{
private static servername = "servername";
private static dbname = "testdb";
private static username = "username";
private static password = "password";
//Any method here could read the values of the static
//variables that are declared above
}
內重複使用的變量有沒有辦法做同樣的php
如果多正在使用相同的用戶憑據對相同的數據庫進行調用,以便信息不會多次輸入?
本質上是某種數據庫調用的可重用語法,而不是每次需要查詢並返回結果時重新輸入相同的8-10行。
編輯.......
至於可重用的代碼去,我終於找到了這之後更google搜索
http://code.tutsplus.com/tutorials/simple-php-class-based-querying--net-11863
是的,它是隻使用一個搜索離你而去[文檔中](https://secure.php.net/manual/ language.oop5.static.php)... – Blackhole
將'$'放在靜態成員名稱的前面。 –