Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Unanswered: pg_connect problems with php

    Hello (sorry for the imperfect english but i'm italian)
    I'm studying a PHP manual (Professional PHP6 from wrox press) that include only PostgreSQL connection, i'm new from php world and i've some problem with these connection with PostgreSQL, i try this code:
    PHP Code:
    <?php
    $db 
    pg_pconnect("host=localhost port=5432 dbname=postgres user=postgres password=pass");

    $sql 'CREATE TABLE "widget" (
        "widgetid" SERIAL PRIMARY KEY NOT NULL,
        "name" varchar(255) NOT NULL,
        "description" text
        )'
    ;
        
    pg_query($db$sql) or die ("unable to create table");

    echo 
    'success';
    ?>
    The result is a HTTP Error 500, php and apache are correctly configured, i can try all the php functions, but i don't know the correct configuration php-postgresql. With a phpinfo i see a field named "mysqlnd", but i've only install postgresql and never mysql or others.. can you help me please? And if is possible, what can i do for best configuring php for postgresql? Thanks a lot.

    p.s.: Nobody in other forums aswer to me.. please.. help me

  2. #2
    Join Date
    Oct 2010
    Posts
    2
    Ok, now it works.
    I found the right configuring documentation for php/apache/postgree.
    Actually i've php5.33 - Apache 2.2.17 - PostgreSQL 8.3.3
    Here is the link.
    I've also modified the script in:
    PHP Code:
    <?php
    $db 
    pg_connect("host=127.0.0.1 port=5432 dbname=postgres user=postgres password=pass");

    $sql 'CREATE TABLE "widget" ("widgetid" SERIAL PRIMARY KEY NOT NULL, "name" varchar(255) NOT NULL, "description" text)';
        

    pg_query($db$sql) or die ("unable to create table");


    echo 
    'success';

    ?>
    All works good

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •