Session Objects, Dynamic Parameters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Guys can anyone explain why this is returning odd results?

function &getObject($class, $params=NULL) {
	if (!is_array($_SESSION['objects'])) {
		$_SESSION['objects'] = array();
	}

	if (!isset($_SESSION['objects'][$class])) {
		if (is_array($params)) {
                        // this is what is erroring
			$args = implode(", ", array_map("paramType", $params));
			echo $class.'('.$args.')';
			$_SESSION['objects'][$class] =& new $class($args);
		} elseif($params != NULL) {
			$_SESSION['objects'][$class] =& new $class(paramType($params));
		} else {
			$_SESSION['objects'][$class] =& new $class;
		}
	}

	return $_SESSION['objects'][$class];
}

function paramType($var) {
	if (is_string($var)) {
		return "'".$var."'";
	} else {
		return $var;
	}
}

when i call this

$dbParams = array(
	'server' => 'localhost',
	'database' => 'ipro2',
	'username' => 'root',
	'password' => '**********'
);

$db = &getObject('Mysql', $dbParams);
$db->connect();

it seems to take this, (which is the actual call in the getObject function
Mysql('localhost', 'database', 'user', '**********')
it seems that 
'localhost', 'database', 'user', '**********'
is being taken as one parameter, i am guessing because the getObject
function creates it as one string, my question is how can i get this
to think it is different arguments, i keep getting errors like this

mysql error: Unknown MySQL Server Host ''localhost', 'database',
'user', '**********'' (-1)


-- 
Joseph Crawford Jr.
Codebowl Solutions
codebowl@xxxxxxxxx
802-558-5247

For a GMail account
contact me OFF-LIST

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux