Part of the EllisLab Network
   
 
CI 1.7:if dbprefix is set, “$this->db->select” is trying to add dbprefix to its one of mysql funtion parameter.
Posted: 01 November 2008 11:18 AM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  10
Joined  09-06-2008

(first, i’m not an english user. so, please be tolerant about my english. wink)

i’m using CI 1.7.0 and making a bulletin board system with it.
i set dbprefix “m_” in “system/application/config/database.php” and wrote some codes using Active Record Class to get a list of articles.
codes are like this:

$this->db->select("A.id, A.virtualnumber, A.author, A.subject, COUNT(CM.id) AS commentnumbering, A.count, DATE(A.created) AS created");
$this->db->from("board_article AS A");
$this->db->join("board_config AS C", "A.boardid = C.id");
$this->db->join("board_comment AS CM", "A.id = CM.articleid", "LEFT");
$this->db->where("C.identifier", $boardIdentifier);
$this->db->group_by("A.id");
$this->db->order_by("A.created", "DESC");
$this->db->limit($offset, $limit);
$ret = $this->db->get();

and, i expected query like this:

SELECT A.id, A.virtualnumber, A.author, A.subject, COUNT(CM.id) AS commentnumbering, A.count, DATE(A.created) AS created
FROM m_board_article
AS A
JOIN m_board_config
AS C ON A.boardid = C.id
LEFT JOIN m_board_comment
AS CM ON A.id = CM.articleid
WHERE C
.identifier = "notice"
GROUP BY A.id
ORDER BY A
.created DESC
LIMIT 1
, 10;

but i couldn’t get any results from that. so i debugged it using Profiler Class.
Profiler said:

SELECT `A`.`id`, `A`.`virtualnumber`, `A`.`author`, `A`.`subject`, `m_COUNT(CM`.`id)` AS commentnumbering, `A`.`count`, `m_DATE(A`.`created)` AS created
FROM
(`m_board_article` AS A)
JOIN `m_board_config` AS C ON `A`.`boardid` = `C`.`id`
LEFT JOIN `m_board_comment` AS CM ON `A`.`id` = `CM`.`articleid`
WHERE `C`.`identifier` = 'notice'
GROUP BY `A`.`id`
ORDER BY `A`.`created` DESC
LIMIT 1
, 10

you can find what is wrong with this query. see SELECT clause. CI db class added dbprefix to mysql internal function. “m_COUNT(CM.id) AS commentnumbering” and “m_DATE(A.created) AS created” is it.

is it a bug or not?
am i missing something while i’m using this Active Record Class?

thanks.

 Signature 

CI saves me!

Profile
 
 
Posted: 01 November 2008 11:30 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRank
Total Posts:  2828
Joined  01-07-2008

What you need here is the second parameter set to FALSE:

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

 Signature 
Profile
MSG
 
 
Posted: 01 November 2008 11:47 AM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  10
Joined  09-06-2008
inparo - 01 November 2008 11:30 AM

What you need here is the second parameter set to FALSE:

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

i know $this->db->select() has second parameter. i know there are some alternative ways to avoid what i have experienced. but, $this->db->select() is not supposed to add dbprefix to mysql internal functions that are used as its parameters, is it? and, if i could not use these Active Record Class to protect fields by auto escaping or something like that, what is that for?

plus, that solution didn’t work. it still adds dbprefix.

 Signature 

CI saves me!

Profile
 
 
Posted: 02 July 2009 05:11 PM   [ Ignore ]   [ # 3 ]  
Summer Student
Total Posts:  3
Joined  07-01-2009
Pascal Kriete - 01 November 2008 11:30 AM

What you need here is the second parameter set to FALSE:

$this->db->select() accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks. This is useful if you need a compound select statement.

Thanks…worked perfectly!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 819, on March 11, 2010 11:15 AM
Total Registered Members: 120536 Total Logged-in Users: 38
Total Topics: 126598 Total Anonymous Users: 3
Total Replies: 665552 Total Guests: 404
Total Posts: 792150    
Members ( View Memberlist )
Newest Members:  sweeper240andrew nsuntroprachel123Rach123Glenn StavaImfaelSMS!persanulandrewknight