Added: 2 years ago
From: phpclass
Views: 7,230
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (30)

Sign In or Sign Up now to post a comment!
  • 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.

  • You have officially half opened up another world to me... Can you please keep this goin?

  • 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..

  • please - change keyboard!!

    with some softer button pushing.

    absolutely needed!

  • 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 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.

  • @phpclass Okay, thanks :)

  • @phpclass Yeah, the instanciation is the disadvantage :/

  • @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.

  • what I try to accomplish is:

    how does that work with:

    @new mysqli()... within the _dbConnect static function??

  • you have great videos. Thanks!

  • I will try joomla, btw you know a Opensource webshop?

  • Try osCommerce. I heard its pretty decent.

  • nice tutorial, but can you help me with a login system with admin features?

  • Sure. But can you be a little more specific.

  • @phpclass

    so ppl can register and login ind and edit info.

    Admin can ban and add others admin

    Sorry for my bad english.

  • 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.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more