Jump to content

Postgres conversion of OO script


bugfreek1

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.