Page 2 of 2 FirstFirst 12
Results 11 to 17 of 17

Thread: Updating deprecated code for MySQL 5.5.+

  1. #11
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I'm not entirely sure I like OOP better - only where it is more compact. Haven't understood enough of it yet. Seems the benefit is mostly for portability and my sites will never be used with anything but MySQL. Do you use OOP for all your php?
    OOP is in a sense a different perspective on coding-- it's about things, and manipulating properties of those things, rather than step-by-step procedures.
    I should add that I agree with Adrian-- mixing OOP and other code would lead to problems in general. In the case of mysqli where there are equivalent OOP and non-OOP options, though, it's probably fine to switch, since they do exactly the same thing (as long as you check that they really do exactly the same thing!). In general, such equivalent functions won't exist (although in theory you could create them for most operations).

    OOP isn't necessarily about using anything other than MySQL. It's a way to manipulate things ("objects") such as a MySQL connection. I do use OOP when it seems useful; I know others who use it for almost everything. I use it when I want to think about my code in terms of things-- for example, if I want to create a template, I might make that an object (a class called "template") and then manipulate things like $template->footer('some text'), and so forth. Rather than a series of unconnected functions, the result is all tied together with reference to an object like $template.

    I think of OOP as a third level. You can draw a parallel to math sort of like this:
    simple addition = line-by-line procedural code, just the basics; limited and slow
    multiplication = functional programming, loops, and so forth; more powerful, faster
    exponents = OOP: functions within functions, functions with properties, objects you can modify, etc.; abstract and most powerful

    So in the same way that multiplication is more powerful than addition, exponents allow you to manipulate multiplication (2^4 = 2*2*2*2). In the same sense, you can get to that "next level" of programming with OOP and do some very complicated things. Or, in another way, it's just a nice way to think about certain kinds of code.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  2. The Following User Says Thank You to djr33 For This Useful Post:

    kuau (07-24-2013)

  3. #12
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    621
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    Thanks, Daniel. Sounds as if you consider OOP to be a more evolved mode of programming. I guess I haven't seen enough of it to see its power. The concept of manipulating objects sounds a bit like modular programming. Any similarity?

    Are most people moving toward OOP? ie. is the procedural method being phased out? What percentage of programmers are using OOP as opposed to procedural style? Is procedural code considered old-fashioned?

    Mahalo, e

  4. #13
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    621
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    [ I'm actually writing a database for feral cat colony caretakers... the code calculates the numbers in the colonies... might as well use the actual code so I don't have to change it. ]

    It took me a while, but I have upgraded this site to PHP version 5.4.16. So now when I run this code...
    Code:
    $result = $mysqli->query("SELECT COUNT(*) FROM cat"); if($result){ echo $result->fetch_row()[0]; } $result->close();
    I get this error: PHP Fatal error: Call to a member function query() on a non-object

    Thanks for the example of prepared statements. I'll see if I can adapt it to this script as soon as it starts giving a count instead of an error. Thanks.

  5. #14
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Daniel's right about OO: it's not just a coding "style," it's an approach. The example in my last post, for instance, shows mysqli's OO api, but it's still more-or-less functional programming. "Do this, then this, then this."

    As for the "more evolved" comment, no; programming styles aren't really arranged like that. OO allows you to do some pretty cool things, but you have to know when it's "overkill." Procedural, functional, and other styles all have their places, too.

    Quote Originally Posted by kuau View Post
    PHP Fatal error: Call to a member function query() on a non-object
    That means $mysqli is not a mysqli object (most likely, your connection failed).

  6. #15
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    621
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    I have decided to abandon OOP. The connection was working for the other pages, but I just couldn't get that code to work no matter what. I wasted an entire day on it & got zero done except upgrading to PHP 5.4. So I redid the code in procedural style and it is now working. Many thanks to both you and Daniel for explaining OOP to me. It helped me decide that it is not for me. I'm sure if it had worked I would have felt differently, but I just see no point in going through that time-consuming torture. Thanks again for your patience and expert tutoring.

    I hope they never phase out procedural style.

  7. #16
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    For some, OOP is seen simply as better. So they use it all the time.
    But for many, it's just one tool among others.
    I'd say that all of the best programmers are able to use OOP and do sometimes, but it hasn't replaced anything. It has just added to it.
    In the case of MySQL, there may be a bit of logic behind thinking of the connection as an object, but beyond that, I see no reason that it needs to be OOP. Other times you might find that OOP really does the fit the project in a way that other approaches don't.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #17
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    621
    Thanks
    274
    Thanked 14 Times in 14 Posts

    Default

    Well, maybe when the commands work, I'll take another look at it. Until then it is POOP to me.

Similar Threads

  1. Replies: 1
    Last Post: 08-29-2012, 02:36 AM
  2. Replies: 3
    Last Post: 10-23-2008, 03:51 PM
  3. MySQL Problems -> Solving (Always Updating)
    By allahverdi in forum MySQL and other databases
    Replies: 0
    Last Post: 09-09-2008, 06:04 PM
  4. Two dynamic listboxes using AJAX, PHP and MySql updating a textbox
    By johntigner in forum Looking for such a script or service
    Replies: 1
    Last Post: 01-12-2008, 03:38 AM
  5. Updating Text From A MySQL DataBase ?
    By Jamie452 in forum JavaScript
    Replies: 0
    Last Post: 12-24-2007, 10:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •