Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > บทความจากสมาชิก > เปลี่ยนจาก MySQL ไปเป็น MySQLi with Prepare Statement



 
Clound SSD Virtual Server

เปลี่ยนจาก MySQL ไปเป็น MySQLi with Prepare Statement

CWE-89
Improper Neutralization of Special Elements Used in an SQL Command (‘SQL Injection’) (CWE-89): The database server could be compromised or attacked by denial of service due to unvalidated parameters

The validation and sanitization process should be implemented for the user input before processing it (Prepared Statement) or the Type Casting mechanism should be implemented for some input fields. Moreover, the application should conceal any error message, which is generated from the application to be generic error messages and should not reveal any sensitive information such as the type of database, the version of database or any SQL statement error messages.
For PHP programming language, there is PDO function use for protecting the web application from SQL Injection vulnerability.

Reference website:
http://php.net/manual/en/ref.pdo-dblib.php
https://docs.microsoft.com/en-us/sql/connect/php/how-to-connect-using-sql-server-authentication?view=sql-server-2017

Using MySQL:


<?php  
  
$sql = "SELECT * \n";
$sql .= "FROM  tbl \n";
$sql .= "WHERE status = 'active' \n";
$sql .= "ORDER BY name";
$result = mysql_query($sql) or die("<pre>$sql</pre>".mysql_error());
$numrows = mysql_num_rows($result);  

?>



Using PHP MySQLi Prepare Statement:
<?php  
try {	
 $sql = "SELECT * FROM tbl WHERE status = ?";
 $stmt = $con->prepare($sql);
 $stmt->bind_param('s', $status);
 $stmt->execute();
 $result = $stmt->get_result();
} catch(Exception $e) {
 $con->rollback(); //remove all queries from queue if error (undo)
 throw $e;
}

?>


Using PHP PDO_DBLIB:
<?php  
   $serverName = "(local)";   
   $database = "Databasename";  
   try {  
      $conn = new PDO( "sqlsrv:server=$serverName;Database = $database", "Username", "Password");   
      $conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );   
   }  
   catch( PDOException $e ) {  
      die( "Error connecting to SQL Server" );   
   }  
   echo "Connected to SQL Server\n";  
   $query = 'select * from Person.ContactType';   
   $stmt = $conn->query( $query );   
   while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) ){   
      print_r( $row );   
   }  
   $stmt = null;   
   $conn = null;   

?>







   
Share
Bookmark.   

  By : lnw Yod
  Article : บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ
  Score Rating :
  Create Date : 2019-02-22
  Download : No files
Sponsored Links
ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 03
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่