车皮 发表于 2017-3-26 13:13:20

Mysqli for PHP(Data bind)

  Mysqli supply with many new features for the php programming,also it's an OOP.
  The below example can show you some: databind
  $mysqli = new mysqli('localhost', 'aaron', 'xxxxxx', 'amo');
  /* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
  
$stmt = $mysqli->prepare("INSERT INTO user(name,password)VALUES (?, ?)");
$stmt->bind_param("ss",$name, $password);  # "ss" on behalf of  string(name) string(password)
  $name = "KEN";
$password = "121312";
  /* execute prepared statement */
$stmt->execute();
  printf("%d Row inserted.\n", $stmt->affected_rows);
  /* close statement and connection */
$stmt->close();
  /* Clean up table CountryLanguage */
$mysqli->query("DELETE FROM USER WHERE NAME='Bavarian'");
printf("%d Row deleted.\n", $mysqli->affected_rows);
  /* close connection */
$mysqli->close();
页: [1]
查看完整版本: Mysqli for PHP(Data bind)