我有一个非常简单的测试脚本:
<?php
$DSN = "mysql:host=db.example.edu;port=3306;dbname=search_data";
try {
$DB = new PDO($DSN, "username", "super-secret-password!");
} catch (PDOException $e) {
header('Content-Type: text/plain');
print "Could not connect to database, rawr. :-(";
exit;
}
$SQL = "SELECT phrase FROM search ORDER BY RAND() LIMIT 10";
foreach($DB->query($SQL) as $row){
print $row['phrase']."\n";
}
?>
Run Code Online (Sandbox Code Playgroud)
当我从命令行执行此脚本时,它完美地工作:
$ php test.php
corporal punishment
Stretches
voluntary agencies and the resettlement of refugees
music and learning
Nike Tiger Woods Scandal
Hermeneia
PSYCHINFO
anthony bourdain
Black-White Couples and their Social Worlds
colonization, …Run Code Online (Sandbox Code Playgroud)