Paso a mostrar las clases.
***DB_Mysql.class***
Código php:
Ver original
class MySQL { private static $_instance = NULL; private $conId; private $host; private $user; private $password; private $database; /***************************************************/ /* <SINGLETON> */ /***************************************************/ { if (self::$_instance == NULL) { self::$_instance = new self($param_db); } return self::$_instance; }//fin getInstance /***************************************************/ /* </SINGLETON> */ /***************************************************/ { { throw new Exception('Invalid number of connection parameters'); } foreach($options as $parameter=>$value) { if(!$value) { throw new Exception('Parametros Invalidos'.$parameter); } $this->{$parameter} = $value; } $this->connectDB(); } // conectar la base de datos private function connectDB() { { throw new Exception('Error al conectar al Server'); } { throw new Exception('Error al seleccionar la Base de datos'); } } // ejecutar consulta public function query($query) { { throw new Exception('Error performing query'.$query); } return new Result($this,$this->result); } } ****Factory.class***** class Db_Factory { // The factory method public static function &factory($type, $param_db) { { //$classname = MySQL::getInstance($param_db); return $classname; } else { throw new Exception ('Driver not found'); } } } ****Result.class**** class Result { private $mysql; private $result; { $this->result=$result; } // fetch row public function fetchAll() { //return mysql_fetch_assoc($this->result); } return $rows; } // numero de registros devueltos public function countRows() { throw new Exception('Error counting rows'); } return $rows; } // count affected rows public function countAffectedRows() { throw new Exception('Error counting affected rows'); } return $rows; } // get insert ID public function getInsertID() { throw new Exception('Error getting ID'); } return $id; } // seek rows public function seekRow($row=0) { if(!int($row)||$row<0){ throw new Exception('Invalid result set offset'); } throw new Exception('Error seeking data'); } } // return result set public function getResult() { return $this->result; } }
¿Como usar ?
Código php:
Les agradeceria que pudieran encontrar alguna solucionVer original
'user'=>$db_user, 'password'=>$db_password, 'database'=>$db_database); // conectar a MySQL $db = Db_Factory::factory('MySQL',$param_db); try { $resultado = $db->query($consulta); /***aca el problema***/ $ultimoId = $db->getInsertID() ; //extraigo el ultimo id } catch(Exception $e) { echo $e->getMessage(); }
Muchas gracias por la ayuda..