Jump to content

[SOLVED] Warning: pg_exec(): supplied argument is not a valid PostgreSQL link resource


Ekate

Recommended Posts

Hello,

I'm getting the following error when I'm running the script:

Warning: pg_exec(): supplied argument is not a valid PostgreSQL link resource

My code:

function getId()
{
	$serial=$this->serial_number;
	$result= pg_exec($db_handle,"select id 
					         from gifts 
						 where serial_number = '$serial';") or die('Query failed.'.pg_last_error()); ///Error message
                                                                                                                                                        ///points to this line
	if (pg_numrows($result) == 1)
	{return pg_result($result,0,'id');}else {return 'Error';};
}

 

Could you please point me why?

Thank you,

BR,

Ekate

Thanks a lot,

I just have to move the project from MySQL to Postgre...

One more stupid question if you don't mind,

if I have class and a lot of functions, and every funcrion looks like this getId, will I have to declare this variable $db_handle as global for every function, or there is another smart way?

 

Thank you,

BR,

Ekate

you'll have too... I think you can put it in the $GLOBALS array that should make it global but not too sure its been a long time since I used global variable totally avoid them causes all mess in the code.. better pass it by param or make it a member variable of the class if your using a class

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.