Re: sql command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



At 09:08 AM 5/3/2002 +1000, Chris Smith wrote:


Could someone explain to me why sql commands work in php with pgsql?

?? Why wouldn't they? :P

I'm too new at this to understand. That's why I ask. What I don't understand is this: is sql generic as opposed to specific comands in mySQL and/or postgreSQL? I now understand that in my problem below you are right, there was an sqlconnect function created as you suggested below. Then, what would be the reason to use this sqlconnect function rather than pg_connect? Can't parameters be passed on to the pg_connect in the same way as they are passed on to the created sqlconnect? It seems like extra work or a bit of redundancy in creating a function that exists?

It looks like the author wrote a function called 'sqlconnect' which takes an array of data to (obviously) connect to the server.

The function would probably look something like this:

function sqlconnect($connectionarray) {
pg_connect("host=$connectionarray['server'] user=$connectionarray['user'] password=$connectionarray['password'] dbname=$connectionarray['database']");
}

(with more error checking and comments of course).

This is what I found (the MySQL references are there because the db was migrated from MySQL to PostgreSQL):

function SQLConnect($params='') {
    global $dbh;
    /*
     * MySQL equivalent:
     *  $dbh=mysql_pconnect( $db_server,$db_user,$db_password );
     */
    if(isset($params['server'])) {
        $connect="host=".$params['server'];
    }
    else {
        $connect='host=localhost';
    }
    if(isset($params['port'])) {
        $connect.=' port='.$params['port'];
    }
    else {
        $connect.=' port=5432';
    }
    if(isset($params['user'])) {
        $connect.=' user='.$params['user'];
    }
    if(isset($params['database'])) {
        $connect.=' dbname='.$params['database'];
    }
    if(isset($params['password'])) {
        $connect.=' password='.$params['password'];
    }
    $dbh=pg_pconnect($connect);
}

Thanks,
Philip



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux