Como rodar comandos no PDO
try {
$hostname = “sqlserver01.bancodedados.com”;
$dbname = “nomebanco”;
$username = “nomebanco”;
$pw = “senha”;
$pdo = new PDO (“mssql:host=$hostname;dbname=$dbname”,”$username”,”$pw”);
} catch (PDOException $e) {
echo “Erro de Conexão ” . $e->getMessage() . “\n”;
exit;
}
$query = $pdo->prepare(“select Coluna FROM nome_tabela”);
$query->execute();
$hostname = “sqlserver01.bancodedados.com”;
$dbname = “nomebanco”;
$username = “nomebanco”;
$pw = “senha”;
$pdo = new PDO (“mssql:host=$hostname;dbname=$dbname”,”$username”,”$pw”);
} catch (PDOException $e) {
echo “Erro de Conexão ” . $e->getMessage() . “\n”;
exit;
}
$query = $pdo->prepare(“select Coluna FROM nome_tabela”);
$query->execute();
for($i=0; $row = $query->fetch(); $i++){
echo $i.” – “.$row[‘Coluna’].”
”;
}
echo $i.” – “.$row[‘Coluna’].”
”;
}
unset($pdo);
unset($query);
?>
unset($query);
?>
Comentários
Postar um comentário