The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 17, 2019, 05:42:10 PM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: my framework no worky  (Read 1961 times)
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« on: February 08, 2008, 09:38:58 PM »

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.

Code:
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;
}
}

Code:
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.
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();
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
DangerMouse
Expert
****
Offline Offline

Posts: 244



View Profile
« Reply #1 on: February 09, 2008, 03:44:53 AM »

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
Logged
nutballs
Administrator
Lifer
*****
Offline Offline

Posts: 5627


Back in my day we had 9 planets


View Profile
« Reply #2 on: February 09, 2008, 08:00:34 AM »

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.
Code:

    public function listparentphrases()
    {
$sql = 'select * from sometable';
$rs = mysql_query($sql,$GLOBALS['database']->conn);
}
Logged

I could eat a bowl of Alphabet Soup and shit a better argument than that.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!