$user='root';
try{
$pdo=new PDO('mysql:host=localhost;dbname=test',$user);
$pdo->exec('set character set utf8');
}
catch(PDOException $e){
echo 'Error: '.$e->getMessage();
}
//using bound variables?
$stmt=$pdo->prepare('insert into test(name) value(:name)');
$stmt->bindParam(':name',$_POST['name']);
$stmt->execute();
//using named parameters
$stmt=$pdo->prepare('insert into test(name) value(:name)');
$stmt->execute(array(':name'=>$_POST['name']));
//using placeholders
$stmt=$pdo->prepare('insert into test(name) value(?)');
$stmt->execute(array($_POST['name']));
//using bound parameters w/ placeholders
$stmt=$pdo->prepare('insert into test(name) value(?)');
$stmt->bindParam($_POST['name']);
$stmt->execute();
我只是想知道作为 PHP 初学者最适合使用什么,我只是对使用什么感到困惑,我想知道什么是最好的和最常用的。