【备忘录】准备Mac中PHP连接到PostgreSQL【PHP】【PostgreSQL】

在Mac的默认PHP环境中无法连接到PostgreSQL的问题。

【情况】在使用PostgreSQL时遇到了数据库连接错误。

当试图通过PHP连接数据库时,出现了以下错误?

  [PDOException]         
  could not find driver 

【解决方案】在这种情况下,你是不是希望可以通过brew轻松安装呢?

使用postgresql

如果使用选项,可以在正在使用的PHP中添加选项,并进行安装。

$ brew update
$ brew upgrade
↑ 最近アップデート、アップグレードしてないわーって方はこちらを

$ brew unlink php71
↑ 使用中のphpをunlinkしないと、コンフリクトしてエラーって言われる場合があります

$ brew reinstall php71 --with-postgresql
$ brew link php71

【補充一下?】出现了不同的错误…

有时会被告知没有ZLIB。

$ brew reinstall php71 --with-postgresql
..
省略
..
checking if the location of ZLIB install directory is defined... no
configure: error: Cannot find libz

在那种时候,

$ xcode-select --install

那么,我们来安装吧。

广告
将在 10 秒后关闭
bannerAds