[thelist] Help converting mysql to postgresql

Magnus Østergaard magnus at slackware.adsl.dk
Sat Sep 17 11:16:31 CDT 2005


Hi,

I'm trying to convert a php + mysql script to php + postgresql.

I've changed every 'mysql_*' to 'pg_*' but I think the problem is the
'mysql_fetch_row' which does not seem to be the same as 'pg_fetch_row'.

Here is the code (hope it is not too mangled by the list):

if (strlen($prefix) > 0) {
   $query = sprintf("SELECT city, number FROM %s WHERE city LIKE '%s%%'
LIMIT %d",
	$this->db_table,
	pg_escape_string($prefix),
	$this->suggestion_limit);
  $result = pg_exec($query);
  while ($row = pg_fetch_row($result)) {
    if ($row[1] == 0)
	$row[1] = '';
    else
  $row[1] = number_format($row[1]) . ' result' . ($row[1] != 1 ? 's' :
'');
  $arr[] = $row;
  }
}

I'm running php 4.3.11 and pgsql 7.2

The original code can be seen here:
http://ajax.zervaas.com.au/examples/GoogleSuggestCloneJax/GoogleSuggestCloneJax.class.phps



More information about the thelist mailing list