我想知道是否有人能告诉我是否可以使用 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'
最佳答案
单引号用于初始化语句时出现语法错误。
$cmd = 'psql -U postgres -c "SELECT schema_name FROM information_schema.schemata WHERE schema_name = \'portal\';"';
exec($cmd);
您应该使用 PDO 而不是 exec,但这可能对您有用。
关于php - 使用PHP检查数据库是否存在于postgreSQL中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37948913/