Find the OOP display strategy in tears
1. Basic information
OOP writes conn The class that connects to MySQL, and all the classes in the system that use the database to extends it.
See below for some of these:
Class db{
public $conn;
private static $h = "localhost";
private static $u = "root";
private static $p = "123123";
Public $db = "WMS";//change, in other words, WMS is not fixed, it is a change. User1 login, $db = "user1"; when User2 log in, $db = "User2";
2.
Because the $db is changeable, not fixed. I started with $db=$_session[' user ' but can't use SESSION in class.
How can I do that?
3.
This is the exception.
$obj =new db ($DB);//through destructors. This can not be used. For other reasons, it cannot be used anyway.
------Solution--------------------
1. This completes the Inheritance link class
Require_once ' db.php ';
Class Userdao extends db{}
2.① It's best not to design a database like this, the latter is complicated to expand and maintain, LZ needs to take into account different situations, preferably from multiple tables, or multiple fields.
The value of the ②session is to be passed to the class, first through the PHP processing page (which we generally call the control layer), by means of the method of accessing the class.
For example: User1 log on after processing the page marked 1 before accessing the database to pass 1 into the class so that he knows which database to call, but it is recommended not to design the database too complex
3.LZ Why would you instantiate an object in a destructor? The general destructor is used to destroy the object and free up space. LZ to initialize the object, it should be done in the constructor.
__construct ()
------Solution--------------------
Why not use the constructor ... anyway .....
------Solution--------------------
Didn't you say it?
Write an init function to pass the value
$db = new MyDB ();
$db->init ($dbname);
------Solution--------------------
1 men, man, do not cry ~
2 on these issues, as a study, it is understandable, really to product development, no deep skill, we recommend starting from the use of the framework.
In the framework, usually the DB class will have a good package, you do not have to toss too much.
------Solution--------------------
$obj = new db ();
$obj->db = $_session[' user ');
Since it is the public property, just assign the value directly.
------Solution--------------------
Write an init function to pass the value
$db = new MyDB ();
$db->init ($dbname);
S