PHP Object Interface Primer Tutorial

PostgreSQL Primer Tutorial

PHP Object Interface Primer Tutorial

Today we are going to show a PHP example of object “interface”, and we like the excerpt from the useful link below, which discusses the same “database” interface idea as we are going to tackle today …

The point is – the INTERFACE describes the methods that we need to access our database. It does NOT describe in any way HOW we achieve that. That’s what the IMPLEMENTing class does. We can IMPLEMENT this interface as many times as we need in as many different ways as we need. We can then switch between implementations of the interface without impact to our code because the interface defines how we will use it regardless of how it actually works.

… in that today, on our local MAMP web server, we imagine a web application able to toggle between two different database arrangements for …

  1. PostgreSQL
  2. MySql

… to present some “films” (table) data, as we did a few days ago when we just did a PostgreSQL version with PostgreSQL PHP Tutorial.

So, as you can tell with our PHP source code filminterface.php where we go …


interface Database {
function listFilms();
function addFilm($code, $title, $did, $date_prod, $kind, $len);
function removeFilm($code);
function amendFilm($code, $title, $did, $date_prod, $kind, $len);
}

… with our “Database” interface class, that this interface class shows what functionality occurs in common for classes that “interface” to it via …


class MySqlDatabase implements Database {
// ...
}
class PostgreSQLDatabase implements Database {
// ...
}

Please feel free to examine the code and try a scenario yourself in a Mac OS X MAMP Apache/PHP/MySql (and add your own PostgreSQL (how to install is discussed at PostgreSQL Primer Tutorial way below)) environment.


Previous relevant PostgreSQL PHP Tutorial is shown below.

PostgreSQL PHP Tutorial

PostgreSQL PHP Tutorial

Some time ago we talked about the PostgreSQL database, and showed you some command line (installation and) usage via a MacBook Pro Terminal application’s (bash environment) command line.

So that showed a bit of SQL for PostgreSQL and you can see it is a lot like other database SQL, and am not about to tell you otherwise today.

The only SQL part that may not be transportable to other database SQL today, is the use of the PostgreSQL “to_date()” function, but the lesson is that so much relational database coalesces with the SQL (DML) for …

  • SELECT (query the database) … for reading …
  • INSERT (add record to the database) … for writing …
  • UPDATE (amend a record of the database) … for writing …
  • DELETE (delete record of the database) … for writing (oddly)

… they all have six letters, and know that has made things cute programmatically for me in the past.

So it is good to not let database work phase you for the way you live with it from day to day with the commands above … but what is sometimes more confusing is the way you connect with databases … generally it involves …

  • hostname (and port, perhaps)
  • username
  • password
  • database (mostly)
  • access rules (occasionally)

We’ve talked about PHP and MySql a fair bit at this blog, and the fact is PHP can quite effectively work with PostgreSQL as well, which we show you today with our local (Mac) MAMP local web server, but do not have available at the domain rjmprogramming.com.au, which PHP was not compiled to include module “pgsql” … the PHP command “phpinfo()” will tell you what the state of play is with your Apache/PHP web server with regard to this.

So today, on MAMP, we take up where we left off with PostgreSQL Primer Tutorial as shown below, and write some PHP you could call pg.php to perform SQL (DML) on that “films” table of that tutorial below.

You can INSERT and UPDATE and DELETE to the database, and behind the scenes we SELECT all the database records of the “films” table to keep you up to date with how things sit.

We used the great Gifpal to create an animated GIF (of a MAMP session execution) for your perusal here.

Link to PostgreSQL Database Server more information … via Wikipedia.
Link to PostgreSQL Database Server home … Open Source.
Link to PostgreSQL Database Server … documentation.

Hope you get something out of today’s database (and PHP) offering.


Previous relevant PostgreSQL Primer Tutorial is shown below.

PostgreSQL Primer Tutorial

PostgreSQL Primer Tutorial

Welcome to the PostgreSQL (Database Server) Primer Tutorial.

The PostgreSQL Database Server product is an excellent Open Source database that has been established for many years. PostgreSQL is an object-relational database management system, and read along with Wikipedia, how its emphases are extensibility and standards-compliance.

Doing this tutorial, and please forgive my naivety with PostgreSQL, I was amazed at the DDL similarities with those databases I was more familiar with, namely MySql, MS-SQL, Oracle, Advantage and Access, and can imagine setting up workable systems in a short space of time.

In the primer tutorial you can see early parts of an install to a MacBook Pro and its “psql” command line interface, like the wonderful “sqlplus” interface of Oracle.

Link to PostgreSQL Database Server more information … via Wikipedia.
Link to PostgreSQL Database Server home … Open Source.
Link to PostgreSQL Database Server … documentation.

If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.


If this was interesting you may be interested in this too.

This entry was posted in Database, eLearning, OOP, Tutorials and tagged , , , , , , , , , , , , , , , , . Bookmark the permalink.

36 Responses to PHP Object Interface Primer Tutorial

  1. Excellent site youu have got here.. It’s hard tto find good quality writing like yours these days.
    I honestly appreciate people like you! Take care!!

  2. Thank you for sharing superb informations. Your website is very cool. I’m impressed by the details that you‘¦ve on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my friend, ROCK! I found simply the information I already searched all over the place and just couldn’t come across. What an ideal web-site.

  3. *This is the proper blog for anyone who wants to find out about this topic. You realize so considerably its almost hard to argue with you (not that I in fact would wantÒ€¦HaHa). You undoubtedly put a new spin on a subject thats been written about for years. Wonderful stuff, just great!

  4. Ella says:

    Hello, super rozdziaΕ‚. Dawno nie pisaΕ‚em tak fajnego dzieΕ‚a

  5. light says:

    I appreciate you writing your viewpoint.. So happy to possess discovered this post.. Is not it awesome whenever you uncover a fantastic publish? Liking the blog post.. thanks much

  6. Victoria says:

    Witaj, fajny rozdziaΕ‚. OkreΕ›lony czas nie pisaΕ‚em tak fajnego dzieΕ‚a

  7. Isaac says:

    Witaj, ciekawy wpis. JakiΕ› czas nie widziaΕ‚em tak interesujΔ…cego tekstu

  8. Shag Carpet says:

    I’m still learning from you, as I’m trying to achieve my goals. I absolutely love reading everything that is written on your website.Keep the stories coming. I liked it!

  9. Hiya very nice web site!! Man .. Beautiful .. Superb .. I’ll bookmark your website and take the feeds additionallyΒ‘KI’m satisfied to seek out numerous useful info right here in the submit, we want develop more techniques on this regard, thank you for sharing. . . . . .

  10. An impressive share, I just now given this onto a colleague who had previously been doing small analysis about this. Anf the husband the fact is bought me breakfast simply because I stumbled upon it for him.. smile. So permit me to reword that: Thnx for your treat! But yeah Thnkx for spending some time to debate this, I discover myself strongly more than it and enjoy reading far more about this subject. If possible, as you become expertise, might you mind updating your web site with a lot more details? It truly is highly of excellent support for me. Huge thumb up because of this text!

  11. Car says:

    Thanks for your whole efforts on this web page. My mom really loves conducting research and it’s obvious why. We all learn all about the powerful manner you produce effective ideas via your web blog and as well foster contribution from the others on that area so our favorite child has been learning a great deal. Take pleasure in the rest of the new year. You’re the one conducting a great job.

  12. I definitely wanted to compose a simple remark to express gratitude to you for all the precious hints you are posting here. My extensive internet look up has now been honored with sensible facts to share with my companions. I would express that many of us website visitors actually are unequivocally lucky to be in a remarkable place with very many brilliant professionals with insightful advice. I feel very much grateful to have discovered your web page and look forward to many more fabulous times reading here. Thank you once more for all the details.

  13. Business law says:

    you’re actually a just right webmaster. The web site loading speed is amazing. It sort of feels that you’re doing any distinctive trick. In addition, The contents are masterwork. you’ve done a great task on this matter!

  14. consultant says:

    Supporting the page.. regards Appreciate the post you given.. So pleased to possess found this submit.. Isn’t it fantastic once you uncover a great publish?

  15. Minivan says:

    Great awesome issues here. I‘¦m very happy to peer your article. Thank you so much and i am looking forward to touch you. Will you please drop me a e-mail?

  16. find out says:

    Actually useful standpoint, appreciate your blogging.. Wonderful ideas you’ve got here.. Truly appreciate the posting you given.. My personal searches seem total.. thank you.

  17. Thanks for your own hard work on this web page. My mother takes pleasure in working on investigation and it is easy to see why. We notice all of the compelling means you offer advantageous suggestions via your web blog and inspire response from other ones on the area of interest while my girl is really being taught so much. Take pleasure in the remaining portion of the new year. You’re conducting a powerful job.

  18. You completed some fine points there. I did a search on the theme and found most people will have the same opinion with your blog.

  19. Pet Shop says:

    Great awesome issues here. I am very glad to see your article. Thank you a lot and i’m looking forward to contact you. Will you please drop me a e-mail?

  20. Wow! Thank you! I continually wanted to write on my site something like that. Can I include a fragment of your post to my website?

  21. You made some good points there. I looked on the internet for the subject matter and found most individuals will approve with your website.

  22. Employment says:

    I simply couldn’t leave your site before suggesting that I extremely enjoyed the standard information a person provide to your visitors? Is going to be back regularly to check out new posts

  23. I have been reading out some of your posts and it’s nice stuff. I will make sure to bookmark your site.

  24. Hello.This post was extremely remarkable, especially since I was searching for thoughts on this subject last couple of days.

  25. health tips says:

    Thanks a lot for giving everyone remarkably superb opportunity to read articles and blog posts from this site. It’s usually very beneficial and stuffed with amusement for me personally and my office colleagues to search your site the equivalent of 3 times a week to find out the latest guides you will have. And of course, we are actually happy considering the cool things you give. Selected 4 points in this article are without a doubt the best we have all ever had.

  26. Hello. fantastic job. I did not imagine this. This is a great story. Thanks!

  27. Great Β‘V I should definitely pronounce, impressed with your site. I had no trouble navigating through all tabs and related info ended up being truly simple to do to access. I recently found what I hoped for before you know it in the least. Reasonably unusual. Is likely to appreciate it for those who add forums or anything, website theme . a tones way for your customer to communicate. Nice task..

  28. It‘¦s actually a cool and helpful piece of info. I‘¦m satisfied that you simply shared this useful information with us. Please keep us informed like this. Thank you for sharing.

  29. So happy to have discovered this post.. Liking the page.. pleased My searches seem total.. thank you. Loving the publish.. bless you

  30. I do believe all of the ideas you’ve presented in your post. They are really convincing and will certainly work. Nonetheless, the posts are too quick for beginners. May just you please prolong them a little from next time? Thank you for the post.

  31. joyful says:

    My internet browsings seem complete.. thanks. Isn’t it excellent any time you get a great article? I appreciate you discussing your perspective.. Excellent ideas you have here..

  32. We did not understand your second paragraph by any means. What can you mean by that? This really is an interesting subject to me so I want to understand anything that you have to say. We were not capable of obtain quite a few other articles during my search although I’m not quite computer literate so that could be why. I am hoping to see you publishing more frequently.

  33. What i do not realize is in fact how you are not really a lot more well-preferred than you might be right now. You’re so intelligent. You recognize therefore considerably on the subject of this topic, made me personally believe it from numerous various angles. Its like men and women don’t seem to be fascinated until it‘¦s one thing to accomplish with Woman gaga! Your individual stuffs great. Always care for it up!

  34. home says:

    Generally I don’t read article on blogs, but I wish to say that this write-up very pressured me to take a look at and do it! Your writing taste has been surprised me. Thanks, quite great article.

  35. What blogs for political discourse would you advise me to review?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>