Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8065287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:37:13+00:00 2026-06-05T11:37:13+00:00

i have been using codeigniter active record class for database acces, But one thing

  • 0

i have been using codeigniter active record class for database acces, But one thing i want to assure is the database security. My scenario is: I am using this query to access data from database.

$q = $this->db->query("SELECT* FROM mytable WHERE id = '$p'");

After this i use return statement.

return $q->result();

when i load database to my view i encode the array with the json encode function and the json encode function not only shows the value of database table fields but also the table field names.
Is it secure or if not how can i avoid displaying table field names
thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:37:14+00:00Added an answer on June 5, 2026 at 11:37 am

    You can strip the table field names by changing your return statement to:

    return array_values($q->result_array());
    

    Better ways would be to parse the results:

    $q = $this->db->query("SELECT* FROM mytable WHERE id = '$p'");
    $result = $q->result();
    
    $values[] = $result['id'];
    $values[] = $result['column1'];
    $values[] = $result['column2'];
    
    return $values;
    

    or specify which columns you need in the SQL statement in case the schema changes:

    SELECT id, column1, column2 FROM mytable WHERE id = '$p'
    

    Finally, as allen213 mentioned, you should use bindings to prevent injection attacks:

    $sql = 'SELECT * FROM mytable WHERE id = ?';
    $q = $this->db->query($sql, array('id' => $p));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using the CodeIgniter system for a while now - but it
I have been using the encryption class of codeigniter (PHP framework) for a while
I have this syntax for grabbing some data from database, I using codeigniter's active
I have been using CodeIgniter all these while, and have solid foundation in OOP
I am using Codeigniter to develop an application, and have been reading bits about
I have been using play 1.2.5rc4 for development of one app and I have
I have been using CI just fine using the MySQL driver. I want to
I have been developing a login library for a website using CodeIgniter. The authentication
I have been coding in php and using codeigniter as well, never got the
I'm building a site using CodeIgniter and up until now things have been going

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.