0

I need help. I need to get the result of a update sql query using doctrine 1.2

I googled and I found a way to make a native sql query using doctrine

$preparequerystring = "UPDATE mdw_reportes_operacion SET mmaplicado = 2.742495126705653 WHERE id = 5294;";
         $con = Doctrine_Manager::getInstance()->connection();
         $st = $con->executeUpdate($preparequerystring,array(false));
         print_r($st);

I would like to know how to retrieve some information about the query I'm executing. I've tried with

$result = $st->fetch(); 

but it returns a 500 internal server error.

What is the right way to retrieve information about the query when performing an UPDATE query?

j0k
  • 22,600
  • 28
  • 79
  • 90
chepe263
  • 2,774
  • 22
  • 38
  • 1
    fetch is for a select query, to return the results. An update does not produce any results. – Marc B May 05 '12 at 00:18
  • @MarcB best answer so far. But is there anyway to get some answer if the query was successful or not? – chepe263 May 05 '12 at 20:22
  • You should not do Native Update/Insert as it is what `Doctrine ORM` is made for `Associations`. – Broncha May 09 '12 at 12:53

1 Answers1

3

Why not using the default update from doctrine instead of a row sql ?

$q = Doctrine_Query::create()
        ->update('MdwReportesOperacion')
        ->set('mmaplicado', '2.742495126705653')
        ->where('id = ?', array(5294));

$rows = $q->execute();

echo $rows;

Edit:

I didn't know how to retrieve the result from a raw doctrine query, but you still can use pdo query:

// update the way you want to retrieve database information
$database = sfYaml::load(dirname(__FILE__).'/../config/databases.yml');
$param = $database['all']['doctrine']['param'];
$conn = new PDO($param['dsn'], $param['username'], $param['password']);

// and then perform the query and retrieve the result
$rows = $conn->exec("UPDATE mdw_reportes_operacion SET mmaplicado = 2.742495126705653 WHERE id = 5294;");
echo $rows;
j0k
  • 22,600
  • 28
  • 79
  • 90