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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:15:52+00:00 2026-05-21T03:15:52+00:00

I’m trying to learn more about MySQL and how to protect against SQL injections

  • 0

I’m trying to learn more about MySQL and how to protect against SQL injections so my research has brought me to Prepared Statements which seems to be the way to go.

I’m also working on learning how to write Stored Procedures and am now trying to combine the two. There isn’t much info on this though.

At the moment in my PHP test app I have a function that calls an SP with a normal MySQL command like this:

mysql_query("CALL usp_inserturl('$longurl', '$short_url', '$source')");

How can I do the same with MySQLi and a Prepared Statement to make it as safe as possible to injections?

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-05-21T03:15:52+00:00Added an answer on May 21, 2026 at 3:15 am

    You might find the following answer of use:

    MySql: Will using Prepared statements to call a stored procedure be any faster with .NET/Connector?

    In addition:

    GRANT execute permissions only so your application level user(s) can only CALL stored procedures. This way, your application user(s) can only interact with the database through your stored procedure API, they can not directly:

    select, insert, delete, update, truncate, drop, describe, show etc. 
    

    Doesn’t get much safer than that. The only exception to this is if you’ve used dynamic sql in your stored procedures which I would avoid at all costs – or at least be aware of the dangers if you do so.

    When building a database e.g. foo_db, I usually create two users. The first foo_dbo (database owner) is the user that owns the database and is granted full permissions (ALL) so they can create schema objects and manipulate data as they want. The second user foo_usr (application user) is only granted execute permisisons and is used from within my application code to access the database through the stored procedure API I have created.

    grant all on foo_db.* to foo_dbo@localhost identified by 'pass';
    
    grant execute on foo_db.* to foo_usr@localhost identified by 'pass';
    

    Lastly you can improve your code example above by using mysql_real_escape_string:

    • http://php.net/manual/en/function.mysql-real-escape-string.php

       $sqlCmd = sprintf("call usp_inserturl('%s','%s','%s')", 
        mysql_real_escape_string($longurl),  
        mysql_real_escape_string($shorturl), 
        mysql_real_escape_string($source));
      
       $result = mysql_query($sqlCmd);
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.