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
withLoadModule 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.
我刚刚在我的Mac(El Capitan)上设置了Postgres,我试图通过PHP连接到它 ...但是,当我提交样本表单时,我收到“致命错误:调用未定义函数pg_connect()”。 我一直在Stack上研究这个(这就是我到目前为止的方法),但我不确定我需要从哪里开始。 p>
这是我如何把它放在这里 到目前为止... p>
-
我使用自制程序,运行
brew install php55-pdo-pgsql code>。 p > li>
我更新了我的Apache httpd.conf文件,用
LoadModule php5_module / usr / local /替换
LoadModule php5_module libexec / apache2 / libphp5.so code> opt / php55 / libexec / apache2 / libphp5.so code>。 p> li>
我重新启动了Apache。 p> li> ul>
我不确定这里是否有用,但这里是PHP ... p>
$ name = $ _POST ['name'] ; $ species = $ _POST ['species']; $ conn = pg_connect(“host = localhost dbname = menagerie user = root password = ****”); pg_query($ conn,“INSERT INTO宠物(名称,种类)VALUES('$ name','$ species')“); code> pre>
我忽略了什么? 非常感谢。 p> div>
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.