pdoを使ったsql文発行例

try {
$hostname = "servername";
$dbname = "dbname";
$username = "username";
$pw = "password";
$pdo = new PDO ("mssql:host=$hostname;dbname=$dbname","$username","$pw");
} catch (PDOException $e) {
echo "Failed to get DB handle: " . $e->getMessage() . "\n";
exit;
}
$query = $pdo->prepare("select name FROM tbl_name");
$query->execute();
for($i=0; $row = $query->fetch(); $i++){
echo $i." - ".$row['name']."
"; } unset($pdo); unset($query);
http://php.mirror.camelnetwork.com/manual/ja/pdo.query.php


その他

タイトルとURLをコピーしました