But globals are switched off now!
This article is useful, but if you have installed a default PHP 4.2.x, with php.ini, then globals will, by default, now be turned off. This means that the user input form code towards the end of the article, will not add any data, since $submit will now be null. Instead, having first checked that your php.ini has register_globals = off, you will need to place $_POST round all the input variables, include $submit. Eg. $submit becomes $_POST[submit] and $name becomes $_POST[name] (you may have to put quotes round the keys, if you are using a Windoze server). But don't change nextval('addressbook_id_seq') ! Also, if for debugging reasons, you change method from post to get, that will mean changing the autoglobal $_POST to $_GET.
One of the things that is always talked about is the usage of HTTP as a general interface to database applications.
To understand this, you must know that I have worked with several relational databases and interfaces, and one of the properties of these systems is that no matter how the system is built, your application always keeps running. This is essential to create transactions in which people access more than one screen to change data.
Using PHP and postgreSQL, this seems not really feasible,because of the way HTTP works. One has to do all the work in one step, but it does not seem possible to start a transaction and then guide the user through several screens to change something and then at the end conclude the transaction. Due to the request/response nature of HTTP, the connection to the database is lost every time that the CGI program stops.
It seems that the only way out here is making use of an intermediate program which is started when the session is initiated and to which all database commands (initiation, transaction, query, update, etc) are passed by using a session identifier which can talk to the started program.
Consider the problem of a concurrent update to a record in the backend database. First the record is requested and displayed by two clients. Then both clients want to update the value of a field (I worked in business environments, it happens more than once that two people at the same time want to change the same data).
You could go about in two ways : you could lock the record, but since you are using CGI you will have to duplicate locking functionality somewhere in you own code, or you check the contents of your record against the database before the update, but this is also duplication of existing functionality.
postgreSQL has very good functions to handle this rather transparently using 'BEGIN TRANSACTION'. However, doing this via CGI never keeps the state of the database for each client.
The reason why I bring this up is that PHP and postgreSQL should be suited for in-house development of software (I am talking real businesses here, not software manufacturers), but that it seems to me that some of the functionality that I am used to from several other platforms, cannot be easily come by.
Re: But globals are switched off now!
that's right - MySQL rules!
Thank you for posting this tutorial. I was having trouble getting PHP to connect to PostgreSQL following the examples in the PHP docs. I was running redhat 7.3 with the standard PostgreSQL, PHP, Apache packages installed and had PostgreSQL working through psql and JDBC but could not connect using PHP with Apache. I was pretty sure I had everything I needed installed and did not need to recompile from source, but I could not connect to PostgreSQL using the examples in the PHP documentation. I think the problem may have been not using variables for my connection parameters (PHP docs just use user=myusername in the connect string rather than using variables as you did). I copied your example and it worked! This verified my suspicion that my install was OK, and the example was messed up.
The only problems I encountered with your example were that a couple of the pg_* functions in your example had extra underscores in the function names (i.e. pg_num_rows, where mine is pg_numrows). This is likely due to an older version of PHP being included with the RH 7.3 distro, but since I'm a PHP newbie I can't really say. But once I had a connection, the pg_last_error used in your example made it clear what I needed to do. It's damn near impossible to know what the problem is until you get a working connection to PostgreSQL as far as I can see since I haven't found a way to get mod_php to tell me what options are compiled in (or Apache either for that matter). Anyway, thanks again for your tutorial, it saved me much experimentation.
There are few hosting providers for PostgreSQL/PHP. One that's relatively affordable is pgHoster.com. Looks like it comes with phpPgAdmin (like phpMyAdmin). www.pghoster.com
July 19th, 2002, 08:11 AM
the power of PostgreSQL
Having developed with DB2, Oracle 8i, and SQL Server I questioned the abilities of PostgreSQL when a project came across my desk six months ago. This attitude was spawn by my MySQL investigations a year earlier. PostgreSQL has all the functionality that I need for building solid business solutions. When MySQL integrates stored procedures, triggers, and views I will reconsider it as a viable alternative.
July 21st, 2002, 08:14 AM
$submit doesnt work
Pasted the script into the file, just to find out that when the button is pressed, the script reloads and goes right back inte the first section. I am sure its somethin on my server installation part. What can be wrong? THanks
March 11th, 2003, 05:17 AM
lack of schedule handling
I just wonder how close is PostgreSQL to MSSQL, Oracle & BD2?
It still lack of scheduled job handler.
It is Re-active; just a DB.
March 14th, 2003, 01:07 PM
Re: But globals are switched off now!
Of course, globals have *nothing* to do with PostgreSQL, and everything to do with CGI input in PHP.
April 11th, 2003, 08:18 PM
Thanks for the article :) I found it a great help. Nice to find a php/postgres guide in the mysql dominated area.
Something that may come in handy for other ppl . I couldnt get it working first time my apache error log showed
"PHP Fatal error: Call to undefined function: pg_connect()" <snip>
Turned out I hadn't configured php.ini correctly and after changes to the extension_dir= and extension= variables it worked.
Thanks again :)
April 11th, 2003, 08:22 PM
PHP and PostgreSQL
PHP and PostgreSQL
When you talk about PHP and databases, people tend to assume you're talking about MySQL. But hang on to your horses - difficult though it may be to believe, PHP does include support for a number of other databases. One of them is PostgreSQL, the *other* open-source database - and this article tells you everything you need to know about using it with PHP. Read the full article .
Please discuss this article in this thread. You can read the article here .
If you would like to see an article covering a particular topic, please post your request here.