I like this post. this post very important. we can get lot of information thought this post and this site. thanks for giving these information, good luck...!!!!
Informatics Outsourcing - Clinical Data Management Services
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';
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.
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 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.
@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 Well, yeah, but if you call mysql_connect twice, then 2 connections thus 2 links be made right (1 when you call DataManager::getUploadCount() and 1 for DataManager::getUploadImages())? Or will they just reference each other? (in which case, I'd have underesteemed PHP's internal optimization)
@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.
@sachav1993 Yea it is a disadvantage =/. Oh, on your previous question the answer is yes. Using mysql_connection in the static class will create a unique connection each time it is called. I used mysql_connection in this tutorial in order to direct the focus on using a static class. In the next tutorial I am going to show how to create a single and reusable mysql connection throughout your scripts.
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 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.
Oh I see. I could help you but at some point you would probably get lost in the code. If your planning to start a very simple site (e.g. online blog) then I would recommend downloading joomla. Its a powerful content management system that does what your looking for, and can get you up and started in no time.
This has been flagged as spam show
I like this post. this post very important. we can get lot of information thought this post and this site. thanks for giving these information, good luck...!!!!
Informatics Outsourcing - Clinical Data Management Services
kalpanaganeshm 1 week ago
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
nawaryoussef1 4 months ago in playlist More videos from phpclass
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
iceman11a 4 months ago
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.
notjustyeti 6 months ago
You have officially half opened up another world to me... Can you please keep this goin?
mrtrippingballs 7 months ago 2
Subscribed, -> Nice tut! You're professional php developer. At what university have you been?
Ilija26 1 year ago
Will the site be laggy becouse you are connecting to the DB every time you create new function..
7715z 1 year ago
please - change keyboard!!
with some softer button pushing.
absolutely needed!
wzazza 1 year ago 7
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.
mariotejutub 1 year ago
when do you close the connection to the DB?
MrCaper58 1 year ago
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
@phpclass Well, yeah, but if you call mysql_connect twice, then 2 connections thus 2 links be made right (1 when you call DataManager::getUploadCount() and 1 for DataManager::getUploadImages())? Or will they just reference each other? (in which case, I'd have underesteemed PHP's internal optimization)
sachav1993 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
@phpclass Okay, thanks :)
sachav1993 1 year ago
@phpclass Yeah, the instanciation is the disadvantage :/
sachav1993 1 year ago
@sachav1993 Yea it is a disadvantage =/. Oh, on your previous question the answer is yes. Using mysql_connection in the static class will create a unique connection each time it is called. I used mysql_connection in this tutorial in order to direct the focus on using a static class. In the next tutorial I am going to show how to create a single and reusable mysql connection throughout your scripts.
YourGodAlmighty 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
what I try to accomplish is:
how does that work with:
@new mysqli()... within the _dbConnect static function??
donadm 1 year ago
you have great videos. Thanks!
ndableg 1 year ago
I will try joomla, btw you know a Opensource webshop?
Sensity1337 2 years ago
Try osCommerce. I heard its pretty decent.
phpclass 2 years ago
nice tutorial, but can you help me with a login system with admin features?
Sensity1337 2 years ago
Sure. But can you be a little more specific.
phpclass 2 years ago
@phpclass
so ppl can register and login ind and edit info.
Admin can ban and add others admin
Sorry for my bad english.
Sensity1337 2 years ago
Oh I see. I could help you but at some point you would probably get lost in the code. If your planning to start a very simple site (e.g. online blog) then I would recommend downloading joomla. Its a powerful content management system that does what your looking for, and can get you up and started in no time.
phpclass 2 years ago