{"id":15108,"date":"2015-05-29T05:01:43","date_gmt":"2015-05-28T19:01:43","guid":{"rendered":"http:\/\/www.rjmprogramming.com.au\/ITblog\/?p=15108"},"modified":"2015-05-30T21:28:21","modified_gmt":"2015-05-30T11:28:21","slug":"postgresql-php-tutorial","status":"publish","type":"post","link":"https:\/\/www.rjmprogramming.com.au\/ITblog\/postgresql-php-tutorial\/","title":{"rendered":"PostgreSQL PHP Tutorial"},"content":{"rendered":"<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","protected":false},"excerpt":{"rendered":"<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. So that showed a bit of SQL for PostgreSQL and you can &hellip; <a href=\"https:\/\/www.rjmprogramming.com.au\/ITblog\/postgresql-php-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":[4,9,12,37],"tags":[83,84,85,252,299,1576,490,714,723,734,744,1575,932,1558,971,997,1186,1252,1319,1411],"class_list":["post-15108","post","type-post","status-publish","format-standard","hentry","category-animation","category-database","category-elearning","category-tutorials","tag-animated-gif","tag-animation-2","tag-apache","tag-connection","tag-database-2","tag-dml","tag-gifpal","tag-local-web-server","tag-mac","tag-macbook-pro","tag-mamp","tag-pgsql","tag-php","tag-phpinfo","tag-postgresql","tag-programming","tag-sql","tag-terminal","tag-tutorial","tag-web-server"],"_links":{"self":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15108"}],"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=15108"}],"version-history":[{"count":10,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15108\/revisions"}],"predecessor-version":[{"id":15146,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/posts\/15108\/revisions\/15146"}],"wp:attachment":[{"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/media?parent=15108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/categories?post=15108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rjmprogramming.com.au\/ITblog\/wp-json\/wp\/v2\/tags?post=15108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}