dream07769
2016-03-08 14:22
浏览 144
已采纳

PHP到Postgres - 致命错误:调用未定义的函数pg_connect()

I've just set Postgres up on my Mac (El Capitan) and I am trying to connect to it via PHP... however, when I submit a sample form, I get "Fatal error: Call to undefined function pg_connect()". I've been researching this on Stack (which is how I got this far), but I'm not sure where I need to go from here.

Here's how I've put this together so far...

  • I use homebrew, and I ran brew install php55-pdo-pgsql.

  • I updated my Apache httpd.conf file, replacing LoadModule php5_module libexec/apache2/libphp5.so with LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so.

  • I restarted Apache.

I'm not sure if it's helpful here or not, but here's the PHP...

$name = $_POST['name'];
$species = $_POST['species'];

$conn = pg_connect("host=localhost dbname=menagerie user=root password=****");
pg_query($conn, "INSERT INTO pet (name, species) VALUES ('$name', '$species')");

What have I overlooked? Thanks very much.

图片转代码服务由CSDN问答提供 功能建议

我刚刚在我的Mac(El Capitan)上设置了Postgres,我试图通过PHP连接到它 ...但是,当我提交样本表单时,我收到“致命错误:调用未定义函数pg_connect()”。 我一直在Stack上研究这个(这就是我到目前为止的方法),但我不确定我需要从哪里开始。

这是我如何把它放在这里 到目前为止...

  • 我使用自制程序,运行 brew install php55-pdo-pgsql

  • 我更新了我的Apache httpd.conf文件,用 LoadModule php5_module / usr / local /替换 LoadModule php5_module libexec / apache2 / libphp5.so opt / php55 / libexec / apache2 / libphp5.so

  • 我重新启动了Apache。

    我不确定这里是否有用,但这里是PHP ...

      $ name = $ _POST ['name']  ; 
     $ species = $ _POST ['species']; 
     
     $ conn = pg_connect(“host = localhost dbname = menagerie user = root password = ****”); 
    pg_query($ conn,“INSERT  INTO宠物(名称,种类)VALUES('$ name','$ species')“); 
       
     
     

    我忽略了什么? 非常感谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongnuo6310 2016-03-09 03:04
    已采纳

    Well, I don't know if this is the best solution, but I updated my PHP to version 5.6 and that took care of it.

    Documentation here - http://coolestguidesontheplanet.com/upgrade-php-on-osx/

    Hope that is helpful.

    打赏 评论

相关推荐 更多相似问题