json_encode pg_fetch_array

For some reason you need to run the result of pg_fetch_array through a loop and store in another array to be able to encode as JSON … here’s an example: // Connecting, selecting database$dbconn = pg_connect(“host=HOSTNAME dbname=DBNAME user=DBUSER password=PASSWORD”) or die(‘Could not connect: ‘ . pg_last_error()); // Performing SQL query$query = “SELECT * FROM mytable”;$result…

there are so many options with pear’s db library for php, I sometimes forget the optimal code for getting a sql result as an array that I can easily use within php. The code below fully demonstrates connecting to and getting an associative array with an ‘order by’ field as the array key. This code…

postgres to mysql workflow

postgres to mysql workflow 1. Export database from postgres to plain text sql. You should do this with the pgAdmin III tool by right clicking on the db you want to export and choosing “Backup …” this will take you to the following screen, where you should select options as displayed below (notice the “Plain”…

Import/Copy CSV/data to Postgres

I recently was having trouble importing CSV to postgres. The trouble was with empty trailing columns (the first row had an empty trailing column). I found that a tab delimited file (export from excel, using export as ms-dos text) allowed me to avoid warnings about empty columns. was getting this error in postgres while trying…

I had earlier shown how to do an update query based on a field from another table in MS Access. Here is the syntax for postgres: UPDATE to_table SET to_column = from_column from from_table where to_table.primary_key= from_table.foreign_key; handy notes for this query: append in postgres is || (double pipe) cast in postgres is like column_to_cast::type_to_cast