{"id":15177,"date":"2015-06-02T05:01:15","date_gmt":"2015-06-01T19:01:15","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=15177"},"modified":"2015-06-01T13:27:23","modified_gmt":"2015-06-01T03:27:23","slug":"php-object-interface-primer-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-object-interface-primer-tutorial\/","title":{"rendered":"PHP Object Interface Primer Tutorial"},"content":{"rendered":"<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/object_interface.png\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PostgreSQL Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/object_interface.png\" title=\"PostgreSQL Primer Tutorial\" id='iqpasd' onmouseover=\" this.src=this.src.replace('.png','.xgif').replace('.gif','.xjpeg').replace('.jpeg','.xjpg').replace('.jpg','.xpng').replace('.x','.');  \" \/><\/a><p class=\"wp-caption-text\">PHP Object Interface Primer Tutorial<\/p><\/div>\n<p>Today we are going to show a PHP example of object &#8220;interface&#8221;, and we like the excerpt from the <a target=_blank title='Useful link ... thanks' href='http:\/\/php.net\/manual\/en\/language.oop5.interfaces.php'>useful link<\/a> below, which discusses the same &#8220;database&#8221; interface idea as we are going to tackle today &#8230;<\/p>\n<blockquote><p>\nThe point is &#8211; the INTERFACE describes the methods that we need to access our database. It does NOT describe in any way HOW we achieve that. That&#8217;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.\n<\/p><\/blockquote>\n<p> &#8230; in that today, on our local <a target=_blank title='https:\/\/www.mamp.info\/' title='MAMP'>MAMP<\/a> web server, we imagine a web application able to toggle between two different database arrangements for &#8230;<\/p>\n<ol>\n<li>PostgreSQL<\/li>\n<li>MySql<\/li>\n<\/ol>\n<p> &#8230; to present some &#8220;films&#8221; (table) data, as we did a few days ago when we just did a PostgreSQL version with <a target=_blank title='PostgreSQL PHP Tutorial' href='#ppt2'>PostgreSQL PHP Tutorial<\/a>.<\/p>\n<p>So, as you can tell with our PHP source code <a target=_blank title='PostgreSQL PHP Tutorial' href='http:\/\/www.rjmprogramming.com.au\/PHP\/filminterface.php_GETME' title='filminterface.php'>filminterface.php<\/a> where we go &#8230;<\/p>\n<p><code><br \/>\ninterface Database {<br \/>\n  function listFilms();<br \/>\n  function addFilm($code, $title, $did, $date_prod, $kind, $len);<br \/>\n  function removeFilm($code);<br \/>\n  function amendFilm($code, $title, $did, $date_prod, $kind, $len);<br \/>\n}<br \/>\n<\/code><\/p>\n<p> &#8230; with our &#8220;Database&#8221; interface class, that this interface class shows what functionality occurs in common for classes that &#8220;interface&#8221; to it via &#8230;<\/p>\n<p><code><br \/>\nclass MySqlDatabase implements Database {<br \/>\n\/\/ ...<br \/>\n}<br \/>\nclass PostgreSQLDatabase implements Database {<br \/>\n\/\/ ...<br \/>\n}<br \/>\n<\/code><\/p>\n<p>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 <a target=_blank title='PostgreSQL Primer Tutorial' href='#ppt'>PostgreSQL Primer Tutorial<\/a> way below)) environment.<\/p>\n<hr>\n<p id='ppt2'>Previous relevant <a target=_blank title='PostgreSQL PHP Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/postgresql-php-tutorial\/'>PostgreSQL PHP Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gifpal-20150528174303.gif\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PostgreSQL PHP Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/PHP\/postgresql-94of.jpg\" title=\"PostgreSQL PHP Tutorial\" id='ippt' onmouseover=\" this.src=this.src.replace('88of.','89ofx.').replace('89of.','90ofx.').replace('90of.','91ofx.').replace('91of.','92ofx.').replace('92of.','93ofx.').replace('93of.','94ofx.').replace('94of.','88ofx.').replace('ofx.','of.');    \"  \/><\/a><p class=\"wp-caption-text\">PostgreSQL PHP Tutorial<\/p><\/div>\n<p>Some time ago we talked about the PostgreSQL database, and showed you some command line (installation and) usage via a MacBook Pro Terminal application&#8217;s (bash environment) command line.<\/p>\n<p>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.<\/p>\n<p>The only SQL part that may not be transportable to other database SQL today, is the use of the PostgreSQL <a target=_blank title='PostgreSQL to_date() method' href='http:\/\/www.techonthenet.com\/postgresql\/functions\/to_date.php'>&#8220;to_date()&#8221;<\/a> function, but the lesson is that so much relational database coalesces with the SQL (<a target=_blank title='Data Manipulation Language information from Wikipedia ... thanks' href='http:\/\/en.wikipedia.org\/wiki\/Data_manipulation_language'>DML<\/a>) for &#8230;<\/p>\n<ul>\n<li>SELECT (query the database) &#8230; for reading &#8230;<\/li>\n<li>INSERT (add record to the database) &#8230; for writing &#8230;<\/li>\n<li>UPDATE (amend a record of the database) &#8230; for writing &#8230;<\/li>\n<li>DELETE (delete record of the database) &#8230; for writing (oddly)<\/li>\n<\/ul>\n<p> &#8230; they all have six letters, and know that has made things cute programmatically for me in the past.<\/p>\n<p>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 &#8230; but what is sometimes more confusing is the way you connect with databases &#8230; generally it involves &#8230;<\/p>\n<ul>\n<li>hostname (and port, perhaps)<\/li>\n<li>username<\/li>\n<li>password<\/li>\n<li>database (mostly)<\/li>\n<li>access rules (occasionally)<\/li>\n<\/ul>\n<p>We&#8217;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) <a target=_blank title='MAMP' href='https:\/\/www.mamp.info\/'>MAMP<\/a> local web server, but do not have available at the domain rjmprogramming.com.au, which PHP was not compiled to include module <a target=_blank title='PHP pgsql module' href='http:\/\/php.net\/manual\/en\/ref.pdo-pgsql.php'>&#8220;pgsql&#8221;<\/a> &#8230; the PHP command <a target=_blank title='phpinfo()' href='http:\/\/php.net\/manual\/en\/function.phpinfo.php'>&#8220;phpinfo()&#8221;<\/a> will tell you what the state of play is with your Apache\/PHP web server with regard to this.<\/p>\n<p>So today, on MAMP, we take up where we left off with <a target=_blank title='PostgreSQL Primer Tutorial' href='#ppt'>PostgreSQL Primer Tutorial<\/a> as shown below, and write some PHP you could call <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/pg.php_GETME\" title='pg.php'>pg.php<\/a> to perform SQL (DML) on that &#8220;films&#8221; table of that tutorial below.<\/p>\n<p>You can INSERT and UPDATE and DELETE to the database, and behind the scenes we SELECT all the database records of the &#8220;films&#8221; table to keep you up to date with how things sit.<\/p>\n<p>We used the great <a target=_blank title='Gifpal' href='http:\/\/gifpal.com'>Gifpal<\/a> to create an animated GIF (of a MAMP session execution) for your perusal <a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/PHP\/gifpal-20150528174303.gif\">here<\/a>.<\/p>\n<p>Link to PostgreSQL Database Server more information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/PostgreSQL' title='Link to PostgreSQL Database Server more information'>via Wikipedia<\/a>.<br \/>\nLink to PostgreSQL Database Server home &#8230; <a target=_blank href='http:\/\/www.postgresql.org' title='PostgreSQL'>Open Source<\/a>.<br \/>\nLink to PostgreSQL Database Server &#8230; <a target=_blank href='http:\/\/www.postgresql.org\/docs\/' title='PostgreSQL documentation'>documentation<\/a>.<\/p>\n<p>Hope you get something out of today&#8217;s database (and PHP) offering.<\/p>\n<hr>\n<p id='ppt'>Previous relevant <a target=_blank title='PostgreSQL Primer Tutorial' href='https:\/\/www.rjmprogramming.com.au\/ITblog\/postgresql-primer-tutorial\/'>PostgreSQL Primer Tutorial<\/a> is shown below.<\/p>\n<div style=\"width: 230px\" class=\"wp-caption alignnone\"><a target=_blank href=\"http:\/\/www.rjmprogramming.com.au\/Mac\/PostgreSQL\/\"><img decoding=\"async\" style=\"float:left; border: 15px solid pink;\" alt=\"PostgreSQL Primer Tutorial\" src=\"http:\/\/www.rjmprogramming.com.au\/Mac\/PostgreSQL\/PostgreSQL_Primer-13of.jpg\" title=\"PostgreSQL Primer Tutorial\"  \/><\/a><p class=\"wp-caption-text\">PostgreSQL Primer Tutorial<\/p><\/div>\n<p>Welcome to the PostgreSQL (Database Server) Primer Tutorial.<\/p>\n<p>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 <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/PostgreSQL' title='PostgreSQL information from Wikipedia ... thanks.'>Wikipedia<\/a>, how its emphases are extensibility and standards-compliance.<\/p>\n<p>Doing this tutorial, and please forgive my naivety with PostgreSQL, I was amazed at the <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/Data_definition_language' title='DDL information from Wikipedia ... thanks'>DDL<\/a> 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.<\/p>\n<p>In the primer <a target=_blank title='click picture' href='http:\/\/www.rjmprogramming.com.au\/Mac\/PostgreSQL\/'>tutorial<\/a> you can see early parts of an install to a MacBook Pro and its &#8220;psql&#8221; command line interface, like the wonderful &#8220;sqlplus&#8221; interface of Oracle.<\/p>\n<p>Link to PostgreSQL Database Server more information &#8230; <a target=_blank href='http:\/\/en.wikipedia.org\/wiki\/PostgreSQL' title='Link to PostgreSQL Database Server more information'>via Wikipedia<\/a>.<br \/>\nLink to PostgreSQL Database Server home &#8230; <a target=_blank href='http:\/\/www.postgresql.org' title='PostgreSQL'>Open Source<\/a>.<br \/>\nLink to PostgreSQL Database Server &#8230; <a target=_blank href='http:\/\/www.postgresql.org\/docs\/' title='PostgreSQL documentation'>documentation<\/a>.<\/p>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d8452' onclick='var dv=document.getElementById(\"d8452\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"http:\/\/www.rjmprogramming.com.au\/wordpress\/?cat=47\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d8452' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d15108' onclick='var dv=document.getElementById(\"d15108\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=database\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d15108' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n<hr>\n<p>If this was interesting you may be interested in <a title='Click here to see topics in which you might be interested' href='#d15177' onclick='var dv=document.getElementById(\"d15177\"); dv.innerHTML = \"&lt;iframe width=670 height=600 src=\" + \"https:\/\/www.rjmprogramming.com.au\/ITblog\/?tag=MySql\" + \"&gt;&lt;\/iframe&gt;\"; dv.style.display = \"block\";'>this<\/a> too.<\/p>\n<div id='d15177' style='display: none; border-left: 2px solid green; border-top: 2px solid green;'><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Today we are going to show a PHP example of object &#8220;interface&#8221;, and we like the excerpt from the useful link below, which discusses the same &#8220;database&#8221; interface idea as we are going to tackle today &#8230; The point is &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/php-object-interface-primer-tutorial\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,12,28,37],"tags":[85,210,299,1577,714,723,725,744,827,849,875,932,938,971,997,1319,1411],"class_list":["post-15177","post","type-post","status-publish","format-standard","hentry","category-database","category-elearning","category-oop","category-tutorials","tag-apache","tag-class","tag-database-2","tag-interface","tag-local-web-server","tag-mac","tag-mac-os-x","tag-mamp","tag-mysql","tag-object","tag-oop","tag-php","tag-phpmyadmin","tag-postgresql","tag-programming","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15177"}],"collection":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/comments?post=15177"}],"version-history":[{"count":7,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15177\/revisions"}],"predecessor-version":[{"id":15184,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15177\/revisions\/15184"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=15177"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=15177"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=15177"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}