A quick glance reveals that you're not calling printf() properly.
Try something like to start with:
printf("%d rows returned", $num_rows);
But consult the experts, not me, since printf() and sprintf() are BIG powerful, flexible functions:
http://www.php.net/manual/en/function.sprintf.php
Further, you don't just get a result handle, and then go hell-bent-for-election and try to print it to the screen. Result set handles don't work that way. Conversely, result handles provide a 'resource reference' and need to be processed in order to extract the 'user-world' data that lies within. Which is why there are functions pg_fetch_row(), pg_fetch_array(), pg_fetch_object() and pg_free_result().
I kindly suggest you read up on the various PostgreSQL functions while you're learning all about sprintf() and printf(). The PostgreSQL reference can be found at:
http://www.php.net/manual/en/ref.pgsql.php
Have fun...