Digitalocean 远程 psql 数据库与本地 PDO (RedBean php) 脚本
Digitalocean remote psql database with local PDO (RedBean php) script
我已经在 Digitalocean 服务器上配置了我的 psql 数据库以接受远程连接。本地脚本
psql -h addres-to-droplet -U Digitalocean -d Digitalocean_production
非常有效(我收到输入密码的提示)。当我将 php 脚本与 Redbean 一起使用时,出现如下 PDO 错误:
Fatal error: Uncaught exception 'PDOException' with message 'Could not
connect to database (Digitalocean_production).' in
/usr/share/nginx/html/rb.php:830 Stack trace: #0
/usr/share/nginx/html/rb.php(657): RedBeanPHP\Driver\RPDO->connect()
#1 /usr/share/nginx/html/rb.php(854): RedBeanPHP\Driver\RPDO->runQuery('SELECT * FROM u...', Array) #2
/usr/share/nginx/html/rb.php(3306):
RedBeanPHP\Driver\RPDO->GetAll('SELECT * FROM u...', Array) #3
/usr/share/nginx/html/rb.php(10060):
RedBeanPHP\Adapter\DBAdapter->get('SELECT * FROM u...', Array) #4
/usr/share/nginx/html/rb.php(10751): RedBeanPHP\Facade::query('get',
'SELECT * FROM u...', Array) #5 /usr/share/nginx/html/test.php(10):
RedBeanPHP\Facade::getAll('SELECT * FROM u...') #6 {main} thrown in
/usr/share/nginx/html/rb.php on line 830
我的 R::setup 看起来像这样
R::setup( 'pgsql:host=address-to-droplet;dbname=Digitalocean_production', 'Digitalocean', 'Digitalocean');
R::getAll( 'SELECT * FROM users'); --that sql works with psql
尝试创建 PDO 实例,然后将其传递给 redbean 设置函数
$db = new PDO('pgsql:dbname=mydb;host=localhost;user=myuser;password=mypass');
R::setup($db);
我已经在 Digitalocean 服务器上配置了我的 psql 数据库以接受远程连接。本地脚本
psql -h addres-to-droplet -U Digitalocean -d Digitalocean_production
非常有效(我收到输入密码的提示)。当我将 php 脚本与 Redbean 一起使用时,出现如下 PDO 错误:
Fatal error: Uncaught exception 'PDOException' with message 'Could not connect to database (Digitalocean_production).' in /usr/share/nginx/html/rb.php:830 Stack trace: #0 /usr/share/nginx/html/rb.php(657): RedBeanPHP\Driver\RPDO->connect() #1 /usr/share/nginx/html/rb.php(854): RedBeanPHP\Driver\RPDO->runQuery('SELECT * FROM u...', Array) #2 /usr/share/nginx/html/rb.php(3306): RedBeanPHP\Driver\RPDO->GetAll('SELECT * FROM u...', Array) #3 /usr/share/nginx/html/rb.php(10060): RedBeanPHP\Adapter\DBAdapter->get('SELECT * FROM u...', Array) #4 /usr/share/nginx/html/rb.php(10751): RedBeanPHP\Facade::query('get', 'SELECT * FROM u...', Array) #5 /usr/share/nginx/html/test.php(10): RedBeanPHP\Facade::getAll('SELECT * FROM u...') #6 {main} thrown in /usr/share/nginx/html/rb.php on line 830
我的 R::setup 看起来像这样
R::setup( 'pgsql:host=address-to-droplet;dbname=Digitalocean_production', 'Digitalocean', 'Digitalocean');
R::getAll( 'SELECT * FROM users'); --that sql works with psql
尝试创建 PDO 实例,然后将其传递给 redbean 设置函数
$db = new PDO('pgsql:dbname=mydb;host=localhost;user=myuser;password=mypass');
R::setup($db);