Welcome Guest, Not a member yet? Register   Sign In
update query that shows in output profiler not writing to the table
#1

[eluser]Brad K Morse[/eluser]
I enabled the output profiler and it displays the following query:

Code:
UPDATE abs_subprojects SET account_id = '105' WHERE abs_subproject_number = '3CH00002'

but when I view the table in my GUI (sequel pro), it does not reflect the changes that update query should of made.

I did some debug logging and it returns what I expect.

Code:
$sql = 'UPDATE abs_subprojects SET account_id = ? WHERE abs_subproject_number = ?';
$update = $CI->db->query($sql, array($account_id, $row->abs_subproject_number));
if ($CI->db->affected_rows() === 1)
{
log_message('debug', 'abs_subproject_number_condition: ' . $condition);
log_message('debug', 'abs_subproject_number_update: ' . $update);
log_message('debug', 'abs_subproject_number: ' . $row->abs_subproject_number);
return new self($row->abs_subproject_number);
}

Here is the create table query for the table it is trying to save to:

Code:
CREATE TABLE `abs_subprojects` (
  `abs_subproject_number` varchar(8) NOT NULL,
  `account_id` int(10) unsigned DEFAULT NULL,
  `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`abs_subproject_number`),
  UNIQUE KEY `account_id_UNIQUE` (`account_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I have tried this multiple times and nothing seems to work. It writes to other tables in the database with no problem and does not return any errors when it displays the query in the output profiler.

I made sure the db username has every privilege for that table too.
#2

[eluser]InsiteFX[/eluser]
.application/config/profiler.php

Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
| -------------------------------------------------------------------------
| Profiler Sections
| -------------------------------------------------------------------------
| This file lets you determine whether or not various sections of Profiler
| data are displayed when the Profiler is enabled.
| Please see the user guide for info:
|
| http://codeigniter.com/user_guide/general/profiling.html
|
*/
$config['benchmarks']         = true;  // Elapsed time of Benchmark points and total execution time
$config['config']             = true;  // CodeIgniter Config variables
$config['controller_info']    = true;  // The Controller class and method requested
$config['get']                = true;  // Any GET data passed in the request
$config['http_headers']       = true;  // The HTTP headers for the current request
$config['memory_usage']       = true;  // Amount of memory consumed by the current request, in bytes
$config['post']               = true;  // Any POST data passed in the request
$config['queries']            = true;  // Listing of all database queries executed, including execution time
$config['uri_string']         = true;  // The URI of the current request
$config['query_toggle_count'] = true;

/**
* ------------------------------------------------------------------------
* Filename: profiler.php
* Location: ./application/config/profiler.php
* ------------------------------------------------------------------------
*/

Top of index.php I add this:
Code:
/**
*  Profiler - Set to true to enable.
*/
define('PROFILER', false);

In a MY_Controller or your main controller add this:
Code:
// --------------------------------------------------------------------

/**
  *  __construct
  *
  * Class Constructor    PHP 5+
  *
  * @access    public
  * @return \Base_Controller
  */
public function __construct()
{
  parent::__construct();

  // use profiler
  $this->output->enable_profiler(PROFILER);
}

Now all you need to do is set the profiler to true or false in the index.php to run it.
#3

[eluser]Brad K Morse[/eluser]
The profiler runs just fine. I am having an issue with the update query that shows up in the profiler does not update the table.
#4

[eluser]InsiteFX[/eluser]
after you run your query do a:
Code:
echo var_dump($your_query);
exit;

To see if the data is correct.

It would help to see what your query is doing to help better


This is my update method in a MY_Model:
Code:
// -----------------------------------------------------------------------

/**
  * _update()
  *
  * Updates the database record with a where clause and the data.
  *
  * USAGE:
  *
  * $data = array('name' => $name, 'email' => $email, 'url' => $url);
  * $where = array('id' => $id);
  * or
  * _update(array('id' => $id), array('name' => $name, 'email' => $email));
  *
  * @access    public
  * @param $where
  * @param $data
  * @internal param $string
  * @return    void
  */
public function _update($where, $data)
{
  $this->db->where($where);
  $this->db->update($this->table, $data);
}

Replace $this->table with your table name.




Theme © iAndrew 2016 - Forum software by © MyBB