我有一個在mysql中完美工作的例子,但是當我轉換爲postgresql時不起作用。隱藏mysql到postgresql查詢
MySQL代碼:(的index.php):
<?php
require('includes/connection.php');
include('func.php');
?>
<html>
<head>
</head>
<body>
<p>
<form action="" method="post">
<select name="drop_1" id="drop_1">
<option value="" selected="selected" disabled="disabled">Select a Category</option>
<?php getTierOne(); ?>
</select>
</form>
</body>
</html>
MySQL代碼(func.php):
function getTierOne()
{
$result = mysql_query("SELECT DISTINCT tier_one FROM three_drops")
or die(mysql_error());
while($tier = mysql_fetch_array($result))
{
echo '<option value="'.$tier['tier_one'].'">'.$tier['tier_one'].'</option>';
}
}
PostgreSQL代碼:(的index.php):
<?php
require('includes/connection.php');
include('func.php');
?>
<html>
<head>
</head>
<body>
<p>
<form action="" method="post">
<select name="drop_1" id="drop_1">
<option value="" selected="selected" disabled="disabled">Select a Category</option>
<?php getTierOne(); ?>
</select>
</form>
</body>
</html>
PostgreSQL代碼(func.php):
function getTierOne()
{
$sth = $dbh->query("SELECT DISTINCT tier_one FROM three_drops");
while($tier = $sth->fetch())
{
echo '<option value="'.$tier['tier_one'].'">'.$tier['tier_one'].'</option>';
}
}
連接(PostgreSQL系統):
的連接工作,但我得到一個錯誤:調用一個成員函數查詢( )在一個非對象上。
應該因爲現在它不是$胸徑對象初始化的地方?你在connection.php中有什麼?也許只需用pg_query替換$ dbh-> query並用pg_fetch_assoc($ sth)替換$ sth-> fetch? –
我用連接更新我的問題。我嘗試你的建議,但我有相同的結果:調用一個非對象的成員函數pg_query()。 – Sbml