Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 Ekate

Ekate

    Member

  • Members
  • PipPip
  • 24 posts

Posted 12 December 2007 - 04:36 AM

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

#2 rajivgonsalves

rajivgonsalves

    Advanced Member

  • Members
  • PipPipPip
  • 2,166 posts
  • LocationPune, India

Posted 12 December 2007 - 04:38 AM

since you are using it in a function you'll have to mention it as global

function getId()
	{
                 global $db_handle;

Cheers!
Rajiv

// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

#3 Ekate

Ekate

    Member

  • Members
  • PipPip
  • 24 posts

Posted 12 December 2007 - 04:56 AM

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

#4 rajivgonsalves

rajivgonsalves

    Advanced Member

  • Members
  • PipPipPip
  • 2,166 posts
  • LocationPune, India

Posted 12 December 2007 - 05:12 AM

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
Cheers!
Rajiv

// commenting code... nah!!! if it was hard to write, it should be hard to read :P
echo implode('', array_map('chr', explode(',','87,104,105,122,122,107,105,100')));

#5 Ekate

Ekate

    Member

  • Members
  • PipPip
  • 24 posts

Posted 12 December 2007 - 05:32 AM

All right,
thank you very much,

BR,
Ekate




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com