After update codeignitor 3.1.11 there is a database error like
A Database Error Occurred
Error Number: 1146
Table 'db_bill_app.Users' doesn't exist
SELECT COUNT(*) AS `numrows` FROM `db_PaymentHistory` AS `PH` LEFT JOIN
Users AS U ON PH.fk_UserGlCode = U.intGlCode LEFT JOIN ManageAcc AS MA ON
PH.fk_UserGlCode = MA.intGlCode
Filename: D:/wamp/www/project/alpha/system/database/DB_driver.php
Line Number: 691
here is the solution after lots of try
system/database/DB_query_builder.php
in this line
$this->qb_join[] = $join = $type.'JOIN '.$table.$cond;
i have add some code like:
$word = $this->dbprefix;
if(strpos($table, $word) !== false){
$table = $table;
}else{
$table = $word.$table;
}
to add manually prefix before table name.. enjoy
Related
I have 3 table like ts_users , ts_acc_category ts_user
I am trying to join like this
$this->db->select('*');
$this->db->from('ts_voucher');
$this->db->join('ts_users','ts_users.user_id = ts_voucher.id');
$this->db->join('ts_acc_category','ts_voucher.user_id = ts_acc_category.acc_cat_id');
$this->db->where('user_reg_type','bill_party');
And error is
<h1>A Database Error Occurred</h1>
<p>Error Number: 1054</p><p>Unknown column 'ts_voucher.user_id' in 'on clause'</p><p>SELECT *
FROM `ts_voucher`
JOIN `ts_users` ON `ts_users`.`user_id` = `ts_voucher`.`id`
JOIN `ts_acc_category` ON `ts_voucher`.`user_id` = `ts_acc_category`.`acc_cat_id`
WHERE `user_reg_type` = 'bill_party'</p><p>Filename: models/reports/ExpensesModel.php</p><p>Line Number: 32</p> </div>
Please tell me where i am wrong in my code
$this->db->select('tv.*,tu.*,tac.*'); //select field what you might want to select.
$this->db->from('ts_voucher as tv');
$this->db->join('ts_users tu','tu.user_id = tv.id', 'left');
$this->db->join('ts_acc_category as tac','tv.user_id = tac.acc_cat_id', 'left');
$this->db->where('tv.user_reg_type','bill_party');
=>Try this..
$this->db->select('tv.*,tu.*,tac.*'); //select field what you might want to select.
$this->db->from('ts_voucher as tv');
$this->db->join('ts_users tu','tu.user_id = tv.id', 'left');
$this->db->join('ts_acc_category as tac','tv.user_id = tac.acc_cat_id', 'left');
$this->db->where('tv.user_reg_type','bill_party');
you don't user_id field in your ts_voucher table please check that first
I am trying to compare the variable $manager_id is present in pr_resignation_requests as managerid column. If present then return the row else dont. But somehow this query is not working. Tried many things but doesn't work. I know my where clause has the error,
Error is :
Error Number: 1054
Unknown column '1' in 'where clause'
SELECT g.*, userids, resignations_date, reason_type, requested_date, last_status, date_last_status, agreed_date, exit_details, exit_checklist, firstname, lastname, managerid FROM (pr_resignation_requests as g) JOIN pr_users_details as ud ON ud.userid = g.userids WHERE1= 'managerid'
My query is :
function get_resignation_request($id=0)
{
global $USER;
$post_arr = $this->input->post();
$manager_id = $this->get_value_by_id('managerid','users',$this->session->userdata('admin_id'));
$this->db->select('g.*,userids,resignations_date,reason_type,requested_date,last_status,date_last_status,agreed_date,exit_details,exit_checklist,firstname,lastname,managerid');
$this->db->from('pr_resignation_requests as g');
$this->db->where($manager_id, managerid);
//$where = "$manager_id='1'";
//$this->db->where($where);
//$this->db->join('pr_resignation_requests as uds','uds.managerid = ".$manager_id" ');
//$this->db->where($manager_id, managerid);
//$this->db->where($manager_id = managerid);
//$this->db->join($this->myTables['pr_users_details'].' as ud','ud.userid = g.userid');
$this->db->join('pr_users_details as ud','ud.userid = g.userids');
//$this->db->join('pr_users as uds','uds.id = g.managerid');
/*$this->db->join('pr_resignation_type as gt','gt.id = g.sr_type');*/
$query=$this->db->get();
$return = $query->result_array();
return $return;
}
Your query is wrong. In where clause first parameter is table name not the value
$query = $this->db->where('managerid', $manager_id);
I've looked at the other 15 or so answers related to this and haven't come up with an answer that works. Here's the code responsible:
function count_distinct($table, $field, $from, $match, $other='Other'){
try{
$ret = array();
$query = 'SELECT '.$table.'.'.$field.', COUNT(*) AS num FROM '.$from;
$query .= ($match) ? ' WHERE '.$match : '';
$query .= ' GROUP BY `'.$table.'`.`'.$field.'`';
$q = mysqli_query($this->con, $query);
if (!$q) {
throw new Exception('Error executing query ' . $query . ' ' . mysqli_error($this->con));
} else {
...
}
return $ret;
}
catch(Exception $e){... }
}
I've removed some of the processing code which seems to work fine. The inputs for this function are code-generated, not client/user generated, and are free from white space or symbols.
I'm getting this error:
Error executing query SELECT interventions.iTYPE, COUNT(*) AS num
FROM interventions JOIN INC ON INC.form_id = interventions.form_id JOIN FORMS ON INC.form_id=FORMS.form_id WHERE `interventions`.`iCAT` = "IV/IO" AND INC.`Pt.AgeRange` <> "Manikin/Lab" AND FORMS.course_id="15" GROUP BY `interventions`.`iTYPE` Unknown column 'interventions.iTYPE' in 'field list'
The table config is this:
interventions
form_id (int (10))
iCAT (varchar(20))
iTYPE (varchar(20))
Result (tinyint(1))
INC
form_id (int(10))
Pt.AgeRange (varchar(20))
FORMS
form_id (int(10))
course_id (int(20))
etc.
The crazy part is that if I copy/paste the query printed in the error message and run it in Sequel Pro it works fine, error free, and prints the result without a problem.
I'm at my wits end—I've tried restarting the server, changing the order of the field list, removing the GROUP BY clause, adding back ticks, removing them...I'm out of ideas.
I use codeigniter calendar class and i am trying to display all reservations for the current month. In the field where the day is, I may have more than one result,and I would like to display them coma separated.
However, I get the following error message:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationID
Filename: models/reservationcalendarmodel.php
Line Number: 81
A PHP Error was encountered
Severity: Notice
Message: Undefined property: stdClass::$reservationArrivalDate
Filename: models/reservationcalendarmodel.php
Line Number: 81
Error is displayed 10 times ( i expect 9 records from the database)
Here is the (relevant) code from the model:
function getReservations($year,$month) {
$currentHotelUser = $this->session->userdata('currentHotelUser');
$query = $this->db->query(
"SELECT r.*
FROM room r
LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate
FROM reservationroom rr
LEFT JOIN reservation re ON re.reservationID = rr.reservationID
WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))
sq ON sq.roomID = r.roomID
WHERE r.hotelID = ".$currentHotelUser['hotelID']."
AND sq.reservationID IS NOT NULL
");
$cal_data = array();
foreach($query->result() as $row) {
// BELLOW IS THE LINE 81 WHERE THE ERROR IS
$cal_data[substr($row->reservationArrivalDate,8,2)]= $row->reservationID;
}
return $cal_data;
}
function generate($year,$month) {
$cal_data = $this->getReservations($year, $month);
$this->load->library('calendar', $this->conf);
return $this->calendar->generate($year,$month,$cal_data);
}
Here is the (relevant) code from the controller:
$this->load->model('ReservationCalendarModel');
$data['calendar'] = $this->ReservationCalendarModel->generate($year,$month);
Here is the (relevant) code from the view:
echo $calendar;
Did anyone know why do I get the above error?
The problem is you query results not having reservationID and reservationArrivalDate. That is the reason, while looping through you are getting this error. Add these two columns in your main select query
"SELECT r.*, sq.roomID, sq.reservationId
FROM room r
LEFT JOIN (SELECT rr.roomID, re.reservationID,re.reservationArrivalDate
FROM reservationroom rr
LEFT JOIN reservation re ON re.reservationID = rr.reservationID
WHERE re.reservationArrivalDate LIKE('".$year."-".$month."-%'))
sq ON sq.roomID = r.roomID
WHERE r.hotelID = ".$currentHotelUser['hotelID']."
AND sq.reservationID IS NOT NULL
"
here is a snippet of my code using active record to update the item_stock values.
I need to get the item.SKU from item table as selector to my query.
$this->db->join('item','item.item_id = items.item_id')
->join('items','items.stock_id = item_stock.stock_id')
->set('item_stock.stock_quantity','item_stock.stock_quantity + $new_qty',FALSE)
->where('item_stock.colour',$color)
->where('item_stock.size',$size)
->where('item.SKU',$SKU)
->update('item_stock');
$query = $this->db->update('item_stock');
for some reason it lost it's JOIN stack.
Error Number: 1054
Unknown column 'item.SKU' in 'where clause'
UPDATE `item_stock` SET `item_stock`.`stock_quantity` = item_stock.stock_quantity + $new_qty WHERE `item_stock`.`colour` = 'Kuning' AND `item_stock`.`size` = 'XL' AND `item`.`SKU` = 'Wooser-01'
Filename: E:\xampp\htdocs\nekogear\system\database\DB_driver.php
Line Number: 330
any tips how to overcome this problem? thanks before.
*ps = I've try the $this->db->query("query code here") and it works fine, but I want to use the active record style for the consistency.
Call me stupid but hey, it's works!
My "solution" is to include the JOIN in the $this->db->update()
$this->db->set('item_stock.stock_quantity','item_stock.stock_quantity + $new_qty',FALSE)
->where('item_stock.colour',$color)
->where('item_stock.size',$size)
->where('item.SKU',$SKU);
$query = $this->db->update('item_stock JOIN items ON items.stock_id = item_stock.stock_id JOIN item ON item.item_id = items.item_id');
Its equal to the following query
UPDATE `item_stock`
JOIN items ON items.stock_id = item_stock.stock_id
JOIN item ON item.item_id = items.item_id
SET `item_stock`.`stock_quantity` = item_stock.stock_quantity + $new_qty
WHERE `item_stock`.`colour` = 'Kuning'
AND `item_stock`.`size` = 'XL'
AND `item`.`SKU` = 'Wooser-01'
Hope it will helps you too!