Example of mysql parameterized query using php

WBOY
Release: 2016-07-25 08:56:31
Original
1935 people have browsed it
This article introduces an example of performing mysql parameterized query in PHP. Friends in need can refer to it.

Share an example of php mysql parameterized query.

Code:

<?php
//例一
$query = sprintf("SELECT * FROM Users where UserName='%s' and Password='%s'",   
                  mysql_real_escape_string($Username),   
                  mysql_real_escape_string($Password));  
mysql_query($query);  
//例二   
$db = new mysqli("localhost", "user", "pass", "database");  
$stmt = $mysqli -> prepare("SELECT priv FROM testUsers WHERE username=? AND password=?");  
$stmt -> bind_param("ss", $user, $pass);  
$stmt -> execute();
?>
Copy after login


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!