简体   繁体   English

PHP POSTGRESQL 数据库连接

[英]PHP POSTGRESQL database connection

if I use this code to connect database it is showing nothing, if I give wrong database name also it is not showing error I'm using this code in ubuntu 16.04.如果我使用此代码连接数据库,它什么也没有显示,如果我给出错误的数据库名称也没有显示错误我在 ubuntu 16.04 中使用此代码。 path var/www/html路径 var/www/html

<?php
//dvdstoredbfunctions.php
// Global Variables
$host="localhost";
$port="";
$db_name="dvd_store";
$options="";
$tty="";
$db_user="dvd_user";
$db_password="";
$err_mesg;
$db_conn;

You have to use pg_connect to connect to postgresql .您必须使用pg_connect连接到postgresql If you want to use PDO see this article , or php documentation .如果你想使用PDO看这篇文章,或者php 文档 For pg_connect , I suggest you to do this:对于pg_connect ,我建议你这样做:

$conn_string = "host=".$host." port=".$port." dbname=".$db_name." user=".$db_user." password=".$db_password;
$db_conn = pg_connect($conn_string);

If it's not connecting try to change $port to 5432 .如果没有连接,请尝试将$port更改为5432 5432 is default port value of postgresql . 5432postgresql的默认端口值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM