PHP Tutorial: Data Management Class
Uploader Comments (phpclass)
Top Comments
-
please - change keyboard!!
with some softer button pushing.
absolutely needed!
-
You have officially half opened up another world to me... Can you please keep this goin?
All Comments (30)
-
very nice tutorial and I really hard to find such tutorials like this, I am almost finishing my frist book about php and databases, so after that I am gonna watch all video you are published here, I am sure all of them are powerful like this one, thanks
-
Hi! PHPClass, Thanks for the tutorial. I just have one question for you. I wanted the _DbConnect() to read values passed in from a config.php file. For some reason, I can't get the class to read the values.
$settings['db_host']; $settings['db_name']; $settings['db_user']; and $settings['db_pass']; I have this at the top of the php script before the class. require_once 'config.php';
Thanks
Joe
-
Thx. You should cap this example off by making the table-name and column-names as parameters to the functions -- then people can actually re-use the code w/o modification for *any* db table.
-
Subscribed, -> Nice tut! You're professional php developer. At what university have you been?
-
Will the site be laggy becouse you are connecting to the DB every time you create new function..
-
To find out how many images have you uploaded isn't enough mysql_num_rows()?
I think it would be more easy than the example that you gave. Nice tutorial though.
-
when do you close the connection to the DB?
Nice tutorial, one thing though: why are you using static methods?
Because, isn't calling self::_dbConnect() at every method going to use up a lot of resources, especially if the MySQL server is remote?
What I personally would do, is create a private attribute ($mysql_link for instance), and assign its value to a connection in __construct(), and use this connection link whenever I need it in the class.
Of course, I'd have to instanciate though, since I'd be using $this->mysql_link.
sachav1993 1 year ago
@sachav1993 Actually, this tutorial is a complement of another tutorial I will be releasing soon that has to do with the PDO connection class. I stated this in the tutorial at 0:50. It will be replacing the normal mysql_connect with a PDO class object. This object will check whether a connection has already been established. If so then return the connection reference. If not, then return a new connection.
phpclass 1 year ago
@sachav1993 Also, the mysql connection automatically closes at the end of every script. So, the use of mysql_connect in this static class is no different if you were to use mysql_connect at the top of a script. Hence,there is no extra resources being used. The method used in the tutorial allows programmers to limit the amount of code duplication and increases code re-usability, efficiency, and simplicity.
phpclass 1 year ago
@sachav1993 There is also the problem of having to instantiate an object every time you want to connect to a database. It is conventionally approached that way, but as you start to learn more about OO PHP, you will realize that it is not a flexible approach. Remember, just because it OO PHP doesn't mean that everything has to be an object. There are static, abstract, interfaces, etc that a lot of people do not know how to really use.
phpclass 1 year ago
First I want to say how helpful these tutorials are. It is very difficult to extrapolate information from books on OOP PHP. Hey, is "DataManager::_DBConnect" the same as say "$a = new DataManager(); $a->_DBConnect" or "self::_DBConnect" the same as "$this->DBConnect()"?
budarmstrong 1 year ago
@budarmstrong Hello, thank you for your question. Unfortunately, you cannot access dbConnect() function through a class object because it is a static function. Static functions are usually known as standalone class functions that do not depend on any class methods or class members. Static function are easier to access because you do not need to create a class object to access them. I hope that answered your question.
phpclass 1 year ago