使用PHP检查postgreSQL中是否存在数据库

问题描述 投票:0回答:3

我想知道是否有人能够告诉我是否可以使用PHP来检查postgresql数据库是否存在?

我正在编写一个PHP脚本,我只希望它创建数据库,如果它尚不存在,但到目前为止还没有看到如何实现它。

谢谢


我试过了

$cmd = 'psql -U postgres -c "SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'portal';"';
    exec($cmd);

我有

PHP Parse error:  syntax error, unexpected 'portal'
php sql database postgresql
3个回答
1
投票

这是一个PHP错误,你必须逃脱'\'门户'''

© www.soinside.com 2019 - 2024. All rights reserved.