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 6662901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:26:26+00:00 2026-05-26T02:26:26+00:00

I just discovered this, I use MySQL as my database. When i do something

  • 0

I just discovered this, I use MySQL as my database.

When i do something like:

$query = $this->db->where('id', '6rubbish')->get('posts', 1);

it generates and executes this SQL:

SELECT *
FROM (`posts`)
WHERE `id` =  '6rubbish'
LIMIT 1

The surprising thing is that it actually fetches the post with the ID 6.

I find this very vulnerable in same cases because i’m trying to exactly match the ID, not to do a LIKE query.

Any ideas?

  • 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-05-26T02:26:26+00:00Added an answer on May 26, 2026 at 2:26 am

    Yes.

    • Read Type Conversion in Expression Evaluation
    • Use intval() PHP function to extract the integer part of the variable
    • Or use is_int to exclude any variable that is not a pure integer

    But the origin of the problem is that your query generator library doesn’t understand the variable types, PHP being a dynamic typed language doesn’t help too.

    I don’t know what library you’re using, maybe there is an option to tell that you’re passing an int? It should protect you from SQL injection, I hope, try with:

    $query = $this->db->where('id', "don't")->get('posts', 1);
    

    and see if the generated SQL has the single quoted escaped (doubled or preceded by backslash).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just discovered a bug where the code looked something like this: char *foo
I just discovered that when Language Extensions are disabled in MSVC, you get this
I just discovered this component and started working with it. I understand that the
I just discovered, quite by accident, that this seems to work: Public Interface Ix
I just discovered MacRuby / HotCocoa and really like the sound of what they're
I've just discovered oh-my-zsh, but I can't get it to work. While themes work
I just discovered that the iframe version of the Facebook Like button doesn't honor
I have just discovered this feature. Declaring an interface using the @interface syntax allows
I've discovered this idiom recently, and I am wondering if there is something I
I've just discovered the NppExec console in Notepad++, which I would really like to

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.