Re: MySQL --> PostgreSQL with PHP

Поиск
Список
Период
Сортировка
Искать
От
Mark Kelly
Тема
Re: MySQL --> PostgreSQL with PHP
Дата
Msg-id
201010082347.06627.pgsql@wastedtimes.net
Ответ на
MySQL --> PostgreSQL with PHP (Helgi Örn Helgason)
Список
Дерево обсуждения
MySQL --> PostgreSQL with PHP Helgi Örn Helgason <sacredeagle@gmail.com>
Re: MySQL --> PostgreSQL with PHP Mark Kelly <pgsql@wastedtimes.net>
Re: MySQL --> PostgreSQL with PHP Helgi Örn Helgason <sacredeagle@gmail.com>
Re: MySQL --> PostgreSQL with PHP Mark Kelly <pgsql@wastedtimes.net>
Re: MySQL --> PostgreSQL with PHP Helgi Örn Helgason <sacredeagle@gmail.com>
Hi.

On Friday 08 Oct 2010 at 22:42 Helgi Örn Helgason wrote:

> Hi!
> Anyone who can spot what I'm doing wrong here?

[big snip]

Try this (easier for me to show than explain):

//============ START CODE ===================
// Connect to the PostgreSQL server
// Build a string to specify the connection parameters, NOT pass them as args.
$connectionString = "host=$hostName dbname=$databaseName ".
	"user=$username password=$password";
if (!$connection = pg_connect($connectionString)) {
	die("Cannot connect: ".pg_last_error());
}

// Run the query on the connection
$query = "SELECT * FROM timmar";
// You had $connection and $query in the wrong order here.
if (!$result = pg_query ($connection, $query)) {
	die("Query failed: ".pg_last_error());
}

// Display the results
displayTimmar($result);
//============ END CODE ===================

I added some error feedback that I suspect may come in useful while you are 
working on the code, removed some @ and () you didn't need, and added some {}.

For full details of the pg_* commands start here:
http://uk.php.net/manual/en/ref.pgsql.php

For the functions you are using, here:
http://uk.php.net/manual/en/function.pg-connect.php
and here:
http://uk.php.net/manual/en/function.pg-query.php

If the table is small (I assume it is since you are sticking the whole thing 
in a HTML table) you might also want to consider fetching all the results at 
once with pg_fetch_all then using a simple foreach in displayTimmar() rather 
than hitting the database for each row individually.

Cheers,

Mark
В списке pgsql-novice по дате отправления
От: Helgi Örn Helgason
Дата:
Сообщение: MySQL --> PostgreSQL with PHP
От: richard terry
Дата:
Сообщение: Like and Not LIke
FAQ