Code: Select all
<?php
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$city = "Amersfoort";
/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "SELECT District FROM City WHERE Name=?")) {
/* bind parameters for markers */
mysqli_stmt_bind_param($stmt, "s", $city);
/* execute query */
mysqli_stmt_execute($stmt);
/* bind result variables */
mysqli_stmt_bind_result($stmt, $district);
/* fetch value */
mysqli_stmt_fetch($stmt);
printf("%s is in district %s\n", $city, $district);
/* close statement */
mysqli_stmt_close($stmt);
}
/* close connection */
mysqli_close($link);
?>Code: Select all
$username = "somename";
$passwd = "somepass";
// Check if username is unique
$stmt = mysqli_prepare($conn, "select verify from users where user_name=? and password=sha1(?)");
mysqli_stmt_bind_param($stmt, "ss", $username, $passwd);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $verify);
mysqli_stmt_fetch($stmt);
echo "The registration varification is ".$verify."<br />";
// Close the statement
mysqli_stmt_close($stmt);
// Close the link
mysqli_close($conn);cheers,
Rick