bugfreek1 Posted March 7, 2007 Share Posted March 7, 2007 All-- I'm a relative newbie to Postgres and am working on teaching myself OO coding. While working through a tutorial, I've run into bumps on a conversion of an OO database connection class from MySql to Postgres. Specifically, my pg_fetch_array function is failing miserably seemingly no matter what I do. Any help to complete this conversion so I can continue on my tutorial would be greatly appreciated. The Code: <? require_once 'SystemComponent.php'; class DbConnector extends SystemComponent { var $theQuery; var $link; //*** Function: DbConnector, Purpose: Connect to the database *** function DbConnector(){ // Load settings from parent class $settings = SystemComponent::getSettings(); // Get the main settings from the array we just loaded $host = $settings['dbhost']; $db = $settings['dbname']; $user = $settings['dbusername']; $pass = $settings['dbpassword']; // Connect to the database $this->link = @pg_connect($host, $db, $user, $pass); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return @pg_query($query, $this->linkid); } //*** Function: getQuery, Purpose: Returns the last database query, for debugging *** function getQuery() { return $this->theQuery; } //*** Function: getNumRows, Purpose: Return row count, MySQL version *** function getNumRows($result){ //return mysql_num_rows($result); return @pg_num_rows($result); } function fetchArray($result, $num){ if (!isset($num)) $num = 0; return @pg_fetch_array($result, $num); } } ?> Thank you in advance for any help. Ben Quote Link to comment https://forums.phpfreaks.com/topic/41687-postgres-conversion-of-oo-script/ Share on other sites More sharing options...
btherl Posted March 8, 2007 Share Posted March 8, 2007 I notice you use both $this->link and $this->linkid Apart from that, are you checking that pg_query() returned a resource before calling pg_fetch_array() with it? If pg_query() fails, it will return false. Quote Link to comment https://forums.phpfreaks.com/topic/41687-postgres-conversion-of-oo-script/#findComment-202171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.