#1
  1. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    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.
  2. #2
  3. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Advanced usage


    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.

    Jurgen Defurne
  4. #3
  5. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    Re: But globals are switched off now!


    that's right - MySQL rules!
  6. #4
  7. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    thanks


    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.
  8. #5
  9. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    web hosting


    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
  10. #6
  11. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    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.
  12. #7
  13. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    $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
  14. #8
  15. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    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.
  16. #9
  17. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    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.
  18. #10
  19. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    [no subject]


    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 :)
  20. #11
  21. No Profile Picture
    guest
    Guest
    Devshed Newbie (0 - 499 posts)

    [no subject]


  22. #12
  23. No Profile Picture
    Ducani
    Guest
    Devshed Newbie (0 - 499 posts)

    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 .
  24. #13
  25. No Profile Picture
    Ducani
    Guest
    Devshed Newbie (0 - 499 posts)
    If you would like to see an article covering a particular topic, please post your request here.

IMN logo majestic logo threadwatch logo seochat tools logo