Here is what you are tyring to do ... you must use the [man]create_function/man lambda trick instead of just using a string with the name of the function you want...
next you cannot call the created function directly from a class... so you have to copy it to a variable in the local scope, then call that variable.
however you don't want to do this in general...
instead of trying to map one function dynamically to another you should just have your switch statement call each different pg or mysql function directly and drop the finished thing int $this->dbh or $this->link or whatever....
and you will run into problems as the two main functions you will prob want to implement pg_connect, mysql_connect and sqlite_open each act very differently with different arguments
actually you should look at the basics of the PEAR DB class.. since thats more around the conclusion you want.. instead of using a $this->type variable and putting a gigantic switch statement in each function, it makes a subclass of DB for each database type.. and then in the constructor uses some dubious php tricks to choose the correct subclass to return...
class DB
{
var $db_link;
var $conn;
function DB( $db_host='', $db_user='', $db_pass='', $db_type='' )
{
switch($db_type) {
case 'mysql':
echo 'setting to mysql_connect';
$this->conn = create_function( '$db_host,$db_user,$db_pass', 'return mysql_connect($db_host,$db_user,$db_pass);' );
break;
case 'pgsql':
echo 'setting to pg_connect';
$this->conn = create_function( '$db_user,$db_pass', 'return pg_connect("dbname=$db_user user=$db_user password=$db_pass");' );
break;
default:
die('type is bad');
return false;
}
$func = $this->conn;
$this->db_link = $func($db_host, $db_user, $db_pass) or die('Opps died');
return $this->db_link;
}
}
$db = new DB();
$dbh = $db->DB('localhost','ednark','mypassword','pgsql');
print '<pre>';
print_r($dbh);
print '</pre>';