Wednesday 14 December 2016

Prepare Statement Select Mysqli

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Girfa : My SQLi Tutorial</title>
</head>

<body><?php
$servername 
"localhost";
$username   
"root";
$password   
"";
$dbname     
"tmp";

// Create connection
$mysqli = new mysqli("localhost""root""""tmp");
/* check connection */
if (
mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

/* create a prepared statement */
$stmt 
$mysqli->stmt_init();
if (
$stmt->prepare("select * from  stu where city=?")) {
  
    
/* bind parameters for markers */
    
$stmt->bind_param("s"$r);
  
    
/* execute query */
    
$r "vns";
  
    
$stmt->execute();
  
  
  
    
$stmt->bind_result($roll$name$city);
  
    
/* fetch value */
    
while ($stmt->fetch()) {
        
printf("<br>Roll=%d<br>Name=%s<br>City=%s<br><br>-----------------------"$roll$name$city);
    }
  
  
  
  
    
/* close statement */
    
$stmt->close();
}

/* close connection */
$mysqli
->close();

?>
</body>


</html>



No comments:

Post a Comment