将mysql转换为postgresql查询

将mysql转换为postgresql查询,mysql,postgresql,Mysql,Postgresql,我有一个例子,它在mysql中运行得非常好,但是当我转换成postgresql时,它就不起作用了 Mysql代码:(index.php): <?php require('includes/connection.php'); include('func.php'); ?> <html> <head> </head> <body> <p> <form action="" method="post">

我有一个例子,它在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>
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>';
    }
}
<?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>
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>';
        }
}
require("constants.php");

    $dbh = new PDO('pgsql:host=' . DB_SERVER . ';dbname=' . DB_NAME, DB_USER, DB_PASS,
    array (PDO::ATTR_PERSISTENT => true ));
    $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

连接正在工作,但我收到一个错误:对非对象调用成员函数query()。

尝试定义$dbh全局值

connection.php:

require("constants.php");
global $dbh;
func.php:

function getTierOne()
{
  global $dbh;

$dbh对象是否应该在某个地方初始化,因为现在它不是?在connection.php中有什么内容?也许只要用pg\u query替换$dbh->query,用pg\u fetch\u assoc替换$sth->fetch($sth)?我用连接更新我的问题。我尝试了你的建议,但我得到了相同的结果:对非对象调用成员函数pg_query()。如果不起作用,我会遇到同样的问题。如果我只选择并回显函数外的行,效果会很好,但在选择框内什么都不会发生。啊,对不起。全球$dbh;需要在函数内部。编辑。