我试图通过仅包含哪些将具有我需要的变量/值来避免硬编码。conf.php
我怎样才能做到这一点?
这是我的conf.php代码
<?php
mysql_connect("localhost", "tiger","tiger") or die (mysql_error ());
mysql_select_db("theaterdb") or die(mysql_error());
?>
其他PHP页面的编码如下:
$q = strtolower(trim($_GET["q"]));
try {
$dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = 'SELECT address FROM theater WHERE LOWER(theater_name) = :q';
$sth = $dbh->prepare($sql);
$sth->bindValue(':q', $q);
$sth->execute();
而不是这一行:
dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
我想使用该conf.php
文件。我将如何做到这一点?