mysqli執行速度更快而且更安全

使用mysqli不但比mysql快,而且能有效防止sql的語句攻擊,還可以使用OO的寫法,簡單記一下使用方式。

$conn=new mysqli('host','user','pw','db');
$id = 7;
$stmt = $conn->stmt_init();
$stmt->prepare("select id,topic from news where id=?");
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->bind_result($col1,$col2);
while ($stmt->fetch())
{
printf("%s %s\n", $col1, $col2);
}
$stmt->close();
$conn->close();

沒有留言: