
![]() |
nutballs
ok im stuck.
its obviously something in the way i am passing the database connection object around. But i really cant figure it out. I have tried a boatload of combos, nothing works. the line where it fails is marked below in the application class. I am doing many other things the same way, by using the $GLOBALS['reference'] to get to class objects from other scopes. Not sure why its not working here. class database { public $conn; function __construct($s,$d,$u,$p,$name) { $this->opendb($s,$d,$u,$p); $GLOBALS[$name] = &$this; } public function opendb($server,$database,$username,$password) { $db = mysql_connect( $server, $username, $password,true) or die('Could not connect to database server.' ); mysql_select_db($database, $db) or die('Could not select database.'); $this->conn = $db; } } class application { public $somevars; function __construct() { $GLOBALS['application'] = &$this; } public function listparentphrases() { $sql = 'select * from sometable'; $rs = mysql_query($sql,$GLOBALS['database']); //********FAILS HERE********** } } this is the page code. require_once('classes/database.class. php');require_once('classes/application.class. php');//initialize objects $database = new database('localhost','somedb','user','pass','database'); //'database'=the global name $application = new application(); $application->listparentphrases(); DangerMouse
I'd guess that its because you're passing an object (your database object) to mysql_query rather than a 'resource identifier'. I think you either need to assign $databaseClass->conn to the global, or pull that property out of the object to pass to mysql_query.
DM nutballs
gah!! thanks, that did it.
i spent 2 damn hours staring at that. i'll blame it on the baby. The fix was in application class, the listparentphrases function. needed the actually property that had the connection assigned to to from the database class. lol. duh. public function listparentphrases() { $sql = 'select * from sometable'; $rs = mysql_query($sql,$GLOBALS['database']->conn); } |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads