PHP mssql_connect issue - php

I'm running this php file:
<?php
$link = mssql_connect('db1.peanut.butter.com:3184', 'user', 'pass');
?>
and getting this error:
Warning: mssql_connect(): Unable to connect to server: db1.peanut.butter.com:3184 in /tmp/query.php on line 3
The server is up and running, and I was able to connect and query it from the SSMS.
How should I write the server in the mssql_connect command?
Full name? Just 'db1'? No port?
Thanks!

This function was removed from PHP 7.0.0
Check if that might be the case.

Related

PHP not connecting to Remote MySQL [duplicate]

This question already has answers here:
php can't connect to mysql with error 13 (but command line can)
(3 answers)
Closed 3 years ago.
I need to connect to a remote MySQL server with PHP but I get the following error:
Warning: mysqli::mysqli(): (HY000/2003): Can't connect to MySQL server on ... (13) in /var/www/html/index.php on line 16
Warning: mysqli::query(): Couldn't fetch mysqli in /var/www/html/index.php on line 17
Fatal error: Call to a member function fetch_assoc() on a non-object in /var/www/html/index.php on line 18
The remote server firewal is open, user has permission to connect from any Host, and I'm able to connect from the local server with mysql command line, but not able to connect with PHP.
What may be the problem here?
EDIT:
Already tried with different connection code, but always same error.
This is the latest one:
$mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS msg");
$row = $result->fetch_assoc();
echo $row['msg'];
Found this to be an issue with SELinux that is not allowing httpd network connections.
Executing:
setsebool -P httpd_can_network_connect=1
Solved the problem.
Make sure you inserted information In the connection info. Replace DB_DATABASE and other keywords with your database info in single quotes.
$mysqli = new mysqli('localhost', 'MyUsername', ''mypassword', 'database1');

SQL Server data to php

I have this php script:
<?php
$server = 'PCCSAF\SQLEXPRESS';
$link = mssql_connect($server, 'username', 'password');
if (!$link) {
die('wrong');
}
?>
I need to connect to local SQL Server express server, but I always get
Fatal error: Call to undefined function mssql_connect() in C:\wamp\www\dbgrab\index.php on line 4
I've tried to install ntwdblib.dll, uncomment extension=php_ming.dll and extension=php_mssql.dll in php.ini, but it still not works.
I'm using PHP 5.4.3 and WAMP server 2.2 on 64bit windows7
Thank you.
WAMP Server x64 is not compatible with PHP SQL Server Driver. Try using 32 bit WAMP.

How connect php and sql server 2008 R2 using wamp server

Already changed file php.ini
And the index.php file contains:
<?php
$server = 'name/SQLEXPRESS';
$link = mssql_connect($server, 'namepc', 'pw');
if (!$link) {
die('Something went wrong');
}
?>
And the error message on the localhost is:
Warning: mssql_connect() [function.mssql-connect]:. (severity 14)
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server:
Something went wrong
Already made it!
Just create a new usser on managment studio and linked it the new accound to your php code.

Why can't I connect to a Sql Server with PHP?

I wrote code as below:
<?php
$conn = mssql_connect("xx.xx.xx.xx", "username", "password")
or die("Can't connect to server ".mssql_error());
echo "Success";
mssql_close($conn);
?>
The error is:
PHP Warning: mssql_connect()
[function.mssql-connect]: Unable to
connect to server: xx.xx.xx.xx in
xxxxxxx\conn.php
on line 2 PHP Fatal error: Call to
undefined function mssql_error() in
xxxxxxx\conn.php
on line 3
The server is Apache2.2, the version of Sql Server is 2005, the version of PHP is 5.2.5, and I remove the ; before extension=php_mssql.dll and there is a php_mssql.dll in the ext directory
Could you check your apache log if there is a problem with the mssql extension when the service starts?
Use mssql_get_last_message()
<?php
$conn = mssql_connect("xx.xx.xx.xx", "username", "password")
or die("Can't connect to server ".mssql_get_last_message());
echo "Success";
mssql_close($conn);
?>

Can't Connect to PostgreSQL with PHP pg_connect()

EDIT: I just realized that this question may be better suited to ServerFault. Instead of copying it, a moderator please move it over? Thanks.
I've checked php-info, and the Postgresql extension is there (pg_connect() is not undefined). I am also able to connect to postgresql using psql on localhost (I've edited my pg_hba.conf file appropriately). Here is the code that's not working:
<?php
$dbconn = pg_connect("host=localhost port=5432 dbname=mydb user=myuser password=mypass") or die('Could not connect: ' . pg_last_error());
?>
This code simply results in "Could not connect: " being displayed in the browser.
I checked my apache log, and here's the relevant error message:
PHP Warning: pg_connect() [<a href='function.pg-connect'>function.pg-connect</a>]:
Unable to connect to PostgreSQL server: could not connect to server: Permission
denied\n\tIs the server running on host "localhost" and accepting\n\tTCP/IP
connections on port 5432?
How can I fix/debug this?
Edit: I'm on Centos 5.4 btw.
could not connect to server: Permission denied
Edit: I'm on Centos 5.4 btw.
Check /var/log/audit/audit.log. Chances are that you're hitting a SELinux rule.

Categories