- प्रत्येक वर्ग के लिए नया कनेक्शन बनाना एक अच्छा विचार नहीं है। यह आपके लिए मॉड्यूलर हो सकता है लेकिन आपका mysql सर्वर जल्द ही
too may connectionsके साथ फूला हुआ होगा त्रुटि।
मेरा सुझाव है कि सिंगलटन पैटर्न और कुछ OO का उपयोग करें।
class Singleton{
private static $instance=null;
public function connection(){
if(self::$instance==null){
self::$instance = mysql_connect(); // define it in your way,
}
return self::$connection;
}
}
class TableA extends Singleton{
function find($id){
$query="select * from `A` where `id`='$id'";
mysql_query($query, $this->connection());
... // other codes
}
}