Jump to content

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

Link to comment
https://forums.phpfreaks.com/topic/41687-postgres-conversion-of-oo-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.