How to print SQL statement in codeigniter model

0 votes

I have a SQL l statement in my model,

I then say:

$query = $this->db->query($sql, array(fields, fields1);

if ($query) {
    return true:
} else {
    echo "failed";
    return false;
}

How can I get PHP to output the precise SQL statement that is being submitted to my database as my query always fails? then show that on my php view, page.

Sep 16 in Database by Kithuzzz
• 12,240 points
16 views

1 answer to this question.

0 votes

To display the query string:

print_r($this->db->last_query());    

To display the query result:

print_r($query);

I hope this helps you. 

answered Sep 17 by narikkadan
• 20,880 points

Related Questions In Database

0 votes
0 answers

How to update two tables in one statement in SQL Server 2005?

In one operation, I want to update ...READ MORE

Aug 20 in Database by Kithuzzz
• 12,240 points
28 views
0 votes
0 answers

How to DROP multiple columns with a single ALTER TABLE statement in SQL Server?

In one ALTER TABLE statement, I would ...READ MORE

Sep 2 in Database by Kithuzzz
• 12,240 points
23 views
0 votes
1 answer

How to sort the data in sql ?

Hi Akash,  If you want to sort ...READ MORE

answered May 29, 2019 in Database by sampriti
• 1,120 points
346 views
0 votes
2 answers

How to select the nth row in a SQL database table?

SELECT * FROM ( SELECT ID, NAME, ROW_NUMBER() ...READ MORE

answered Apr 23, 2020 in Database by anand
• 140 points
17,908 views
+1 vote
1 answer

AWS Pricing VS Google-Cloud-Platform Pricing

The lowest config cost according Google Cloud ...READ MORE

answered Jul 19, 2018 in AWS by Priyaj
• 58,080 points
192 views
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,510 points
437 views
0 votes
1 answer

How to run Django's test database only in memory?

Hello @kartik, If you set your database engine ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,780 points
2,546 views
0 votes
1 answer

How to Specify a mySQL ENUM in a Django model?

Hello @kartik, You can follow this snippet below: MAYBECHOICE ...READ MORE

answered Jun 24, 2020 in Python by Niroj
• 82,780 points
674 views
0 votes
1 answer

How to display databases in Oracle 11g using SQL*Plus

A MySQL "database" can be compared to ...READ MORE

answered Sep 12 in Database by narikkadan
• 20,880 points
51 views
0 votes
1 answer

How to extract only the year from the date in sql server 2008?

To obtain the year from the given ...READ MORE

answered Sep 15 in Database by narikkadan
• 20,880 points
46 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP