ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

What's the right way to prevent SQL injection in PHP scripts?

user-image
تم إضافة السؤال من قبل Khadijah Shtayat , Technical Lead , Opensooq
تاريخ النشر: 2013/09/08
Fadi Alkhateeb
من قبل Fadi Alkhateeb , Senior Front End Developer , NexTwo

Use prepared statements and parameterized queries (PDO & Mysqli).

PDO : http://php.net/manual/en/book.pdo.php

MYsqli : http://php.net/manual/en/book.mysqli.php

 

You can see more informations about it here :

How to Prevent SQL Injection in PHP

 

Mohammad Ateieh
من قبل Mohammad Ateieh , Software Engineering Manager , Bayt.com

in PDO and MySqli you can bind the parameters and then excute the query

another solution you can escape the parameters using "mysql_real_escape_string"

its all depends on what are you using to manipulate the sql statement

Arif Mohammad Mohiuddin
من قبل Arif Mohammad Mohiuddin , Data Entry Chief & Manager , Mohammadia Enterprise

Stored Procedure

 

Muhammed Ajmal Seeraveetil
من قبل Muhammed Ajmal Seeraveetil , Software Engineer , Wipro

Better always use XSS Filtering 

Asif Ahmad Rather
من قبل Asif Ahmad Rather , Senior Software Engineer , Eresolute Consultant and Services pvt ltd.

the best and the simple way is use sql procedures and try to implement strict coding. dont b a loose coder. 

Mohammed Aldini
من قبل Mohammed Aldini , Project Manager/Team Leader/Senior Software Engineer/System Analysis , TechBox Group

use mysql_escape_string function to avoid charectors for sql injection before the string with {} for example:"SELECT *FROM  `tablename`WHERE  fieldname = '{".mysql_escape_string($value)."}'"

Tanweer Ahmed
من قبل Tanweer Ahmed , Application Developer , Department of Revenue,Registration and Land Reforms,Government of Jharkhand

Use Parameterized Query to prevent sql injection

mukhtar ahmed Ibrahim
من قبل mukhtar ahmed Ibrahim , Software engineer , Norwegian tax administration

 

Best way to prevent sql injection is looking for correct input.  Use regular expressions and develop strategy for invalid input. Please remember pitfals. alternative representations. http://myhostname.com or http://194.71.105.29.

Biggest mistake:

.Not checking at all,

.Looking for incorrect input. 

Saad Ibrahim
من قبل Saad Ibrahim , senior web developer , brandusocial

Beside The best things  that all Other developrs mention, the best thing u can do to avoid SQL injection, is FILTER ALL INPUTS , Nerver trust input from user.

One of the ways is using magic quotes at server level. Another one is using the function addslashes for each input, although it's not really nice.

Junais Vaisyar
من قبل Junais Vaisyar , End-User Support , KAUST

use mysql_escape_string function to avoid charectors for sql injection before the string

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟