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, 2022 in Database by Kithuzzz
• 38,000 points
5,056 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, 2022 by narikkadan
• 63,600 points

Related Questions In Database

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
1,270 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
26,952 views
0 votes
1 answer

How to detect a SQL table's existence in Java?

Hello, Depending on the DB, you can do ...READ MORE

answered May 13, 2020 in Database by Niroj
• 82,840 points
1,156 views
0 votes
0 answers

How to add constraints in SQL?

Jan 31, 2022 in Database by Neha
• 9,020 points
473 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,020 points
910 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,520 points
1,035 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,840 points
4,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,840 points
1,552 views
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, 2022 in Database by Kithuzzz
• 38,000 points
871 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, 2022 in Database by Kithuzzz
• 38,000 points
918 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