mssql_connect unable to connect to server - php

I'm trying to connect to a remote sql server database via php in our debian server.
<?php
// Some basic variables
$Server = "myservername";
$User = "myuser";
$Password = "mypwd";
$Database = "facts_sql";
// Connect to the database
$dbconnect = mssql_connect($Server,$User,$Password);
?>
And I got the error.
PHP Warning: mssql_connect(): message: Login failed for user ''. (severity 14) in /var/www/Information.php on line 8
PHP Warning: mssql_connect(): General SQL Server error: Check messages from the SQL Server (severity 14) in /var/www/Information.php on line 8
PHP Warning: mssql_connect(): Unable to connect to server: myservername:1433 in /var/www/Information.php on line 8
Are there any advices? Thanks

Related

how to connect to MySQL databases using php in zend server

I am trying to connect to my MySQL version 8.0.11 database in zend server version 7.2.10 using php but I could not connect it
Warning: mysqli::__construct(): Unexpected server respose while doing caching_sha2 auth: 109 in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Warning: mysqli::__construct(): MySQL server has gone away in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Warning: mysqli::__construct(): (HY000/2006): MySQL server has gone away in C:\Program Files (x86)\Zend\Apache24\htdocs\connectdatabase.php on line 7
Connection failed :MySQL server has gone away
I am getting the following warnings when i try to run my code.
i have searched and tried ALTER USER 'username'#'hostname' IDENTIFIED WITH mysql_native_password BY "userpassword" command but it does not work for me
<?php
$servername = "localhost";
$username = "root";
$password = "hello";
$conn = new mysqli($servername,$username,$password);
if(mysqli_connect_error())
{
die("Connection failed :" . mysqli_connect_error());
}
echo "CONNECTED SUCCESSFULLY";
?>
Try with caching_sha2_password:
ALTER USER 'username'#'hostname'IDENTIFIED WITH caching_sha2_password BY 'userpassword';

SQLSERV in PHP7 not Working

I'm attempting to connect with a Sybase database with PHP7 on Windows Server 2012 R2 using the sqlsrv PDO driver. I've tried a number of connection strings - the following is the most direct connection string I've found that should be at least tossing me an error (an error from PHP) when accessing the page. However, when I access the page it it tells me the page is not working (as in the PHP is not working). PDO SQLSRV is active in my phpinfo(). The PHP Error I receive is:
[18-Nov-2016 22:32:18 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_wincache.dll' - The specified module could not be found.
in Unknown on line 0
And many times in the same log file I am receiving the following error:
[18-Nov-2016 22:31:23 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'C:\Program Files\PHP\v7.0\ext\php_mysql.dll' - The specified module could not be found.
in Unknown on line 0
This is all basically a straight-up install, so I'm surprised that it's tossing back errors about windows cache and mysql (when I'm not even attempting to access a mysql anything). Any leads or information would be great. Thank you for this forum!
<?php
try {
$server_name = "MY\SERVER,1234";
$database_name = "myDatabase";
$username = "myUsername";
$password = "myPassword";
$conn = new PDO("sqlsrv:server=$server_name;database=$database_name", "$username", "$password");
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch( PDOException $e ) {
die( "Error connecting to SQL Server" );
}
echo "Connected to SQL Server\n";
?>

Mysql connection over SSL with PHP mysqli

I'm trying to setup PHP mysqli connection to MariaDB database for two VPS servers and need to encrypt the communications due to it being over public network.
Currently I can connect from the client server to database server via commandline mysql client normally and I have checked via tcpdump that the connection is encrypted. However for some reason I can't figure out the PHP part. It's relatively basic nginx + php5-fpm + mariadb setup but mysql is working on non default port.
Debian Jessie, Php5 5.6.7, Mariadb 10.0.16, nginx 1.6.2
Here's the test script:
<?php
$DB_NAME = '';
$DB_HOST = '111.111.111.111';
$DB_USER = 'username';
$DB_PASS = 'password';
$mysqli = mysqli_init();
if (!$mysqli) {
die('mysqli_init failed');
}
//have tried witha and without the following with multiple variations
$mysqli->ssl_set(NULL, NULL, NULL,'/etc/mysql/ssl/',NULL);
if (!$mysqli->real_connect($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME, 11111, NULL,MYSQLI_CLIENT_SSL )) {
die('Connect Error (' . mysqli_connect_errno() . ') '
. mysqli_connect_error());
}
$query = "SHOW STATUS LIKE 'ssl_cipher'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
if($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
print_r($row);
}
}
else {
echo 'NO RESULTS';
}
mysqli_close($mysqli);
?>
Main error I'm getting without the ssl_set:
2015/07/11 15:58:34 [error] 2857#0: *374 FastCGI sent in stderr: "PHP message: PHP Warning: mysqli::real_connect(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): Cannot connect to MySQL by using SSL in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): [2002] (trying to connect via tcp://192.168.130.123:42139) in /srv/www/test.php on line 15
PHP message: PHP Warning: mysqli::real_connect(): (HY000/2002): in /srv/www/test.php on line 15".....
Any ideas would be appreciated. This is really killing me.
Maybe this problem occurs due to the changes made in PHP 5.6. I guess you are using self-signed certificates? If your DB enables peer_name validation by DEFAULT, there is no way to disable this in PHP. So when generating you certificates you have to use the right "Common Name" for each one:
CA: hostname
Server: FQND, e.g. hostname.example.com
Client: somename
The important part is the server certificate where the Common Name has to be the same as the host you are connecting to.
What it looks like is this
SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
My guess is that you don't have the correct CA set up. Some DB systems (like Amazon Web Services RDS) have their own CA file. You're using the capath argument so make sure the PEM files are in that path. If they are, the next thing I would do is switch to the third argument of ssl_set and specify the PEM file directly
$mysqli->ssl_set(NULL, NULL, '/path/to/ca.pem', NULL, NULL);

Setting up MySQL issue under Eclipse PHP

I have a snippet of code under the PHP file in Eclipse PHP.
$username = mysql_real_escape_string( $username );
It generates an error Warning:
mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /web_development/php_work/new_test/test.php on line 37
Looks like the Eclipse PHP couldn't connect to the MySQL of XAMPP, so How do I fix that?
I added two lines
#mysql_connect('localhost','root', '') or die('Could not connect to : ' . mysql_error());
#mysql_select_db('test') or die( "-Unable to select database");
but Eclipse still throws me.
mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: Can't connect to local MySQL server through socket '/tmp/mysql.sock'
thx.

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.

Categories