Ekate Posted December 12, 2007 Share Posted December 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/81313-solved-warning-pg_exec-supplied-argument-is-not-a-valid-postgresql-link-resource/ Share on other sites More sharing options...
rajivgonsalves Posted December 12, 2007 Share Posted December 12, 2007 since you are using it in a function you'll have to mention it as global function getId() { global $db_handle; Quote Link to comment https://forums.phpfreaks.com/topic/81313-solved-warning-pg_exec-supplied-argument-is-not-a-valid-postgresql-link-resource/#findComment-412701 Share on other sites More sharing options...
Ekate Posted December 12, 2007 Author Share Posted December 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/81313-solved-warning-pg_exec-supplied-argument-is-not-a-valid-postgresql-link-resource/#findComment-412707 Share on other sites More sharing options...
rajivgonsalves Posted December 12, 2007 Share Posted December 12, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/81313-solved-warning-pg_exec-supplied-argument-is-not-a-valid-postgresql-link-resource/#findComment-412714 Share on other sites More sharing options...
Ekate Posted December 12, 2007 Author Share Posted December 12, 2007 All right, thank you very much, BR, Ekate Quote Link to comment https://forums.phpfreaks.com/topic/81313-solved-warning-pg_exec-supplied-argument-is-not-a-valid-postgresql-link-resource/#findComment-412725 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.