Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Conexion{
- protected $_lastid;
- protected $host;
- protected $username;
- protected $password;
- protected $dbname;
- function Conexion(){
- $config = Zend_Registry::getInstance();
- $this->host = ['host'];
- $this->username = ['username'];
- $this->password = ['password'];
- $this->dbname = ['dbname'];
- }
- public function getID()
- {
- return $this->_lastid;
- }
- function transaccion($query,$encodeJSON=false,$encode=false){
- $conexion = @mysql_connect($this->host, $this->username, $this->password);
- @mysql_select_db($this->dbname, $conexion);
- if($encode)
- {
- $executeQueryUTF8Format = @mysql_query('SET NAMES utf8;');
- }
- if( $conexion == false ){ return false; }
- /* Begin transaction. */
- $begin = @mysql_query("BEGIN;");
- /* Execute operations that are part of the transaction. Commit on
- success, roll back on failure. */
- $executeQuery = @mysql_query($query);
- $this->_lastid= @mysql_insert_id();
- //If commit fails, roll back the transaction.
- $commit = @mysql_query("COMMIT;");
- if ($begin && $executeQuery && $commit){
- $data = array();
- while ($row=@mysql_fetch_object($executeQuery)){
- $data [] = $row;
- }
- // Liberar resultados
- @mysql_free_result($begin);
- @mysql_free_result($executeQuery);
- @mysql_free_result($commit);
- // Cerrar la conexi�n
- @mysql_close($conexion);
- if($encodeJSON)
- return json_encode($data);
- else
- return $data;
- }else{
- @mysql_query("ROLLBACK");
- // Liberar resultados
- @mysql_free_result($begin);
- @mysql_free_result($executeQuery);
- @mysql_free_result($commit);
- // Cerrar la conexión
- @mysql_close($conexion);
- return false;
- }
- }
- }
- se usa asi $this->conexion->transaccion("consulta",false,true);//devuelve un array si pone true en el segundo parametro devuelve un json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement