Why do you need classes for PDO?



  • I'm wondering if I should connect to my cms a base class like this. https://github.com/indieteq/PHP-MySQL-PDO-Database-Class or not. Looking at this class, I realized that PDO already had the same thing, so why text it?

    For example:

    // 1. Read friendly method  
    $db->bind("id","1");
    $db->bind("firstname","John");
    $person = $db->query("SELECT * FROM Persons WHERE firstname = :firstname AND id = :id");
    

    So is that:

    $stmt->bindParam(1, $name);
    

    Can you cut me up, please?



  • 99% of PDO classes are not needed.

    Because PDO-- already. class, and to improve it, you need to be Very good. a good programmer. Typically, PDO tracts take curvature nukes that can't work with PDO, don't know the programming azones, and end up getting a curved monster that does more harm than good.

    This class is an example of this approach.

    • he makes mistakes. The centraltaker should be mistaken.
    • He's writing some sort of file in a browser that doesn't have to do at all. Why would a website visitor have to look in the file? Such writings are an indicator of the fact that we have not done a single project. Otherwise, he would have understood that the browser was written for a visitor, not for a programmer.
    • It's not "containing the connection," in the sense that it doesn't guarantee that the only connection to the OBD will be used throughout the crypt. On the contrary, examples show that the author proposes to re-establish the class every time, creating a new connection to the OBD. In the end, the violin will be as many compounds as the descendants of CRUD (usually tens).
    • It duplicates the PDO function, which the author did not seek, for example, the column function.
    • He breaks the PDO, adding some hell in the form. utf8_encode($value); - I mean, it's bluntly messing up the data.
    • Instead of simplifying the PDO syntax, the author complicates it. For example, PDO supports position players, which in most cases significantly reduce the pysanin and do not repeat the same word five times as a second. It's impossible to use them here.
    • By not comprehensing the software, the author makes a classic mistake of all the zeros: he mixes in one class a function that works both with the general connection and with a separate request. What cannot be done categorically, but should be done taking an example with the PDO: a separate compound and separate facilities for each request. It's the only right approach. The first request inside the processing cycle of another request would put this class in a very unpleasant position.

    What is characteristic is that the previous speakers seem to consider all this to merit.

    I recommend you first. http://phpfaq.ru/pdo understand his strengths and weaknesses. For example, how is it right to hold a connection, or to transfer variables everywhere to single The class install or use a service that will store the instans and issue it upon request; how to obtain the data immediately in the right format without using curvatures; how to deal with errors correctly (in general case, it is not necessary, PHP is doing well itself).

    After that, you can either write your class or look for someone else, but you can't do more harm than good.

    Either, as mentioned above, instead of a library for the one-on-one work with the OBD, take a library, which makes it easier for a hundred more things, from the selection of input parameters to the mailing of the Fremfork. It's got to be this one. http://symfony-gu.ru/documentation/ru/html/book/from_flat_php_to_symfony2.html but it's not Symfony, but Laravel, who's based on it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2