Welcome Guest, Not a member yet? Register   Sign In
[Fixed]Transaction problem
#1

[eluser]finord[/eluser]
Fixed the table of the InnoDB database has to be

Hi, I have been trying to use a transaction operation. But because there is no work, because if the second query, it comes out false, the first does not return to its previous value. With the false, the rollback does not occur.

Already in the first table that reduces the amount, and no one receives this amount

The Controller:

Code:
class stock extends Controller{
   function stock(){
      parent::Controller();
      $this->load->database();
   }

function test(){
          $pid="110";
          $delocal="1";
          $alocal="2";
          $pid2="110";
          $pcta="1";
          $this->db->where('pid', $pid);
          $this->db->where('local', $delocal);
          $this->db->select_sum('cta');
          $q1=$this->db->get('pos_stock');
          $this->db->where('pid', $pid2);
          $this->db->where('local', $alocal);
          $this->db->select_sum('cta');
          $q2=$this->db->get('pos_stock');
           foreach ($q1->result() as $row){$dcta=$row->cta;}
           foreach ($q2->result() as $row){$acta=$row->cta;}
          $dacta=$dcta-$pcta;
          $aacta=$acta+$pcta;

$this->db->trans_start();
$this->db->query("UPDATE `asoc`.`pos_stock` SET `cta` = $dacta WHERE `pos_stock`.`pid` =$pid AND
`pos_stock`.`local`=$delocal");

$this->db->query("UPDATE `asoc`.`pos_stock` SET `cta` = $aacta WHERE `pos_stock`.`pid` =$pid AND
`pos_stock`.`local`=$aDlocal"); //I put the wrong name of "local"
                                //to see what happened if there was a failure
$this->db->trans_complete();

          $this->db->where('pid', $pid);
          $this->db->where('local', $delocal);
          $qw3=$this->db->get('pos_stock');
          $this->db->where('pid', $pid);
          $this->db->where('local', $alocal);
          $qw4=$this->db->get('pos_stock');
          $datos['d']=$dcta;
          $datos['a']=$acta;
          $datos['qw3']=$qw3;
          $datos['qw4']=$qw4;
          $this->load->view('ts', $datos);

}

}


And the view
Code:
<?

$this->load->helper('url');
foreach ($qw4->result() as $row) {
    $prc=$row->cta;
echo $prc."===>";
}
foreach ($qw3->result() as $row) {
    $pprc=$row->cta;
echo $pprc;
}

?>

And here is the mysql code:
Code:
-- phpMyAdmin SQL Dump
-- version 2.11.8.1deb1
-- http://www.phpmyadmin.net
--
-- Servidor: localhost
-- Tiempo de generación: 27-06-2009 a las 17:07:20
-- Versión del servidor: 5.0.67
-- Versión de PHP: 5.2.6-2ubuntu4.2

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Base de datos: `asoc`
--

-- --------------------------------------------------------

--
-- Estructura de tabla para la tabla `pos_stock`
--

CREATE TABLE IF NOT EXISTS `pos_stock` (
  `pid` int(11) NOT NULL,
  `cta` varchar(255) NOT NULL,
  `local` varchar(255) NOT NULL,
  `hora` time NOT NULL,
  `fecha` date NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Volcar la base de datos para la tabla `pos_stock`
--

INSERT INTO `pos_stock` (`pid`, `cta`, `local`, `hora`, `fecha`) VALUES
(109, '64', '', '00:00:00', '0000-00-00'),
(110, '830', '1', '00:00:00', '0000-00-00'),
(110, '978', '2', '00:00:00', '0000-00-00');

I have tried to use $this->db->trans_start(TRUE) , but still failing.

If anyone can help me, I would greatly appreciate
#2

[eluser]finord[/eluser]
Go'm an idiot, so much time on it and thought I had forgotten to change the table to InnoDB >.<

sorry, if they can delete the post, but may serve if someone else commits the same error




Theme © iAndrew 2016 - Forum software by © MyBB