« Return to Thread: undefined method DB_mssql::lastInsertId() ??

undefined method DB_mssql::lastInsertId() ??

by clone45 :: Rate this Message:

Reply to Author | View in Thread

Hello! I'm constantly running in to these types of issues. I must be doing something fundamentally wrong. I've instantiated a database connection like so:

// ----------------------------------------------------------------------
$dsn = $config->dbadaptor . "://"       // Build a DSN string (Data Source Name)
	 . $config->username . ":"        // Required by DB::connect()
	. $config->password . "@" 
	. $config->host . "/" 
	. $config->dbname;
 
	$db = DB::connect($dsn, TRUE);
		
	if (DB::isError($db)) {
		die($db->getMessage());
	}  
    
$this->db = $db;	
// ----------------------------------------------------------------------


Later in my code, I do something like this:

// ----------------------------------------------------------------------
$sql = "INSERT INTO $table_name (" . implode(',',$transformed_keys) . ') VALUES ( ' . implode(',',$values) . ' ) ';

$result = $this->db->query($sql);		
$id = $this->db->lastInsertId();
// ----------------------------------------------------------------------

Unfortunately, I get the error, "undefined method DB_mssql::lastInsertId()". What am I doing wrong?
Thanks!
- Bret

 « Return to Thread: undefined method DB_mssql::lastInsertId() ??