Why can I not connect to my PostgreSQL database with PHP? - php

I have recently attempted to install a postgresql database on a digital ocean droplet running Ubuntu 18.04 x64
Using PgAdmin on my local PC, I can connect fine to the database.
Using my own C# tool on my local PC, I can connect fine to the database.
Using PHP on another server however, I cannot connect and upon checking the error log I have receiving this -
[19-Jan-2019 16:32:55 UTC] PHP Warning: pg_connect(): Unable to
connect to PostgreSQL server: could not connect to server: Connection
refused Is the server running on host "178.62.42.168" and
accepting TCP/IP connections on port 5432?
My PHP code is as follows, credentials adjusted for posting here but are correct.
<?php
$db = pg_connect("host=hostip port=5432 user=sam password=sensoredpassword dbname=sam ") or die('connection failed');
?>
Port 5432 is open.
I have adjusted /etc/postgresql/10/main/postgresql.conf >>> "listen_addresses = '*' and uncommented.
I have adjusted /etc/postgresql/10/main/pg_hba.conf and added >>> host all all 0.0.0.0/0 md5
Why can I not connect with PHP but I can connect with other tools and languages? Could something on the server the PHP is running on be blocking the connection?

Related

when I start apache MySQL server, I get error " (HY000/2002): No connection could be made because the target machine actively refused it."

after the start apache server, i could not access PHPMyAdmin. when i try to access i get an error and auto-stop MySQL server.
- mysqli_real_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it.
- Connection for controluser as defined in your configuration failed.
mysqli_real_connect(): (HY000/2002): No connection could be made
because the target machine actively refused it.
- phpMyAdmin tried to connect to the MySQL server, and the server
rejected the connection..
how can i solve this error
Add below line under config.inc.php
$cfg['Servers'][$i]['port'] = 8111;
If you are on Windows os and the above solution does not work, just check if your mysql is running with "netstat -ano" command, if the services are not running just try starting the mysql service.

How can fix error PDOException: could not find driver?

I have local site in Wamp32, apache 2.4.23, php 7.0.10 and mysql 5.7.14
I wrote program to connect to sql server 2014 in another server but when I run this program it has an error
"could not find driver"
In php.ini I have:
extension=php_sqlsrv_7_ts.dll
extension=php_pdo_sqlsrv_7_ts.dll
My command for connect to sql server is:
$connection = new PDO('sqlsrv:Server=myserverIP;Database=mydatabase', 'username', 'password');
My server OS is windows server 2012R2

How to connect from cakePHP3 to MSSQL Server

(I develop on a Windows System with XAMPP and use cakePHP3)
I want to connect from my cakePHP3 Localhost application, to a external SQL Server (installed on a external Windows Server 2012 r2).
In my app.php I config my Server and that is how I test the connection:
try {
$connection = ConnectionManager::get('sqlServer');
$connected = $connection->connect();
}catch (Exception $connectionError) {
echo "not";
}
echo "connected";
On testing I get this error:
A Database connection using was missing or unable to connect.
The database server returned this error: SQLSTATE[IMSSP]: This extension requires the Microsoft ODBC Driver 11 for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver 11 for SQL Server for x86: http://go.microsoft.com/fwlink/?LinkId=163712
So I go to my Server and Installed the needed extensions (ODBC Driver 11 for SQL Server). But I get still the same Error.
Is it possible to connect to the external Server from Localhost? Or did I make a mistake?

Failed to connect to: localhost:27017: Connection refused

I have installed MongoDB in xampp on Ubuntu using Laravel 5.1. But I always get this error
MongoConnectionException in TestController.php line 19: Failed to
connect to: localhost:27017: Connection refused
Nor I'm able
I have gone through a lot of questions, but all proved to be trivial solution.
Please help me with this as I'm stuck on it.
I think that first thing to do is to ssh on that server and check that mongod process is alive, then try open mongo shell using command - mongo . If all works try telnet on this server and port from your machine ,if there is no errors , read mongo logs

Unable to connect SQL SERVER 2008 R2

i have one page for register ... all my config is right but my register.php can't connect to my sql server..
Error
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: x.x.x.x in C:\xampp\htdocs\rfweb\regis.php on line 81
code in line 81 is
$connectsql=mssql_connect($db_host, $db_user, $db_pass) or die('<center><b>'.$lang_error_cant_connect1.'</b><br>'.$lang_error_cant_connect2.'<br><br>Back</center>');
spesification :
SQL SERVER 2008 R2 and xampp 1.6
i've try to setting ODBC, Restart SQL, ect
anyone help me to fix it?
Try sqlsrv queries instead of mssql, and make sure you properly configured the ports of your xampp. Another thing, try to check whether you have IIS, maybe it's blocking your xampp.

Categories