PHP pdo_dblib extension works via HTTP but not via CLI - php

One of our customers uses the pdo_dblib PHP extension to connect to an external Sybase database using FreeTDS.
The connection works perfectly through HTTP requests, but when he calls the PHP script through CLI (using PHP binary), the connection fails:
SQLSTATE[HY000] Unable to connect: Adaptive Server is unavailable or does not exist (connection_name) (severity 9)
The strange thing is that running through root user works, but not through their user.
Worth mentioning that this is hosted on a cPanel server, so maybe it has something to do with it.

Related

PHP Can't connect to external Mysql after apt upgrade

Using Ubuntu 16.10
I have been using external Mysql server just fine, but today I did an apt update and apt upgrade, after that. PHP simply won't connect to external mysql server anymore. I can connect the server via command line using mysql though, but php just does not. I tried simple script to open to connection and
mysqli_connect_error(); just gives out an error "connection refused"
Ports are open. Any idea why this suddenly happened after an update?
EDIT: Updated the client server. The server where external mysql is running works fine, I can connect to it from other servers. But one client server where php script runs can't access it after an update.
Found it. php 7 does not support ip:port anymore, but port has to be set up separately. Changed the default port via: ini_set('mysqli.default_port', 'port'); in the file where connection was made as I was unable to change it in the script I am using.

How to Skip Secure Auth - MySQL 5.6.15 using php?

I am trying to access a third party database and having the following error:
Warning: mysql_pconnect(): mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
but I am able to access the database through command prompt by using following command:
mysql -uTheUseerNAme -pThePassword DbName -h HostName --skip-secure-auth
Note: here in the above command I am using --skip-secure-auth to access the database. But now my question is can we do the same thing in php while making connection with database in config.php file?
With newer versions of PHP (5.6) and mysqli drivers, the default for connecting to MySQL server is to use secure authorization (TLS). It appears that when using an older MySQL server, this will fail.
It doesn't seem that there is a way from within PHP to disable the authentication on connection.
The current workaround is to add this to your MySQL server config (typically found in /etc/mysql/my.cnf or /etc/my.cnf).
[mysqld]
skip-secure-auth
This will disable secure auth from the server side, forcing newer clients (case in point newer versions of PHP/mysqli) to skip the secure auth when connecting, effectively replicating the --skip-secure-auth on all connecting clients.
As a possible workaround without changing the MySQL server config, it appears there is a MYSQLI_OPT_SSL_VERIFY_SERVER_CERT option that can be set on the mysqli connection instance via mysqli_options().
mysqli_options($conn, MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, false);
Setting this to false should yield the behavior you are looking for, although there are reports that this does not work and in our testing it did not in fact work.
There appears to have been an update which was pushed to PHP 5.6.16 and later which resolves this issue. My guess is that you are running something between PHP 5.6.0 and 5.6.15.

PHP CLI can't connect to any network address

I'm facing a strange problem with PHP CLI.
PHP runs perfectly fine when accessing files through the web browser. I can run CURL scripts, connect to databases and perform any kind of connection available on PHP, either locally or to external addresses.
But if I run the same script on CLI, I always get the following error:
Warning Error: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Host desconocido. in ...
This is a global problem, and it's not related to my scripts, because if I run, for example, the installation for composer, I get the same error while trying to install.
I tried reinstalling WAMP, going back to the default PHP.ini and enabling IPv6. I compared the ini values on CLI and on normal mode (through ini_get_all()) and there were no differences, besides the normal ones.
I'm running WAMP latest version, on Windows 8 x64.

C++ Program Calls PHP Script To Upload Content to Database

Say I have a C++ program that any user can download on their machine. I'd like to give the user the capability to upload content via this program to some remote database that I've set up.
My strategy is to have the C++ program call a PHP script that will connect to the database when prompted. However when I attempt to connect to a remote server that isn't localhost like the following call:
mysql_connect("website.com", "user", "pass");
It gives the error:
PHP Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial
communication packet', system error: 111
Is there some way to allow any user who downloads this program the ability to connect and upload content? Further more, is there a better way that could also work? Thanks.
If you want to directly upload from the user's machine why use PHP? Use the mysql C API. Just enable remote access in the mysql server.
But I won't advise to do that, it's better to have your own webserver, with it's "local" mysql, and then you won't have connection problems and expose your DB server to the outer world.

Can't Run PHP cURL in IIS Web App, But Can From CLI

I'm running 5.2.14 with IIS on Windows 7. Used the Windows Platform Installer.
When I write a script that uses cURL or file_get_contents() and run it via the commandline, everything works great.
If I use the same code in a web page, running in IIS, the request always fails. cURL returns a response code of 0. file-get_contents comes back with "Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known". I even tried putting the code in a separate script and running it via exec() to pipe the output back to my web script. But the script, which works fine from the CLI, fails when called by a PHP script being executed by IIS.
php.exe -i returns no errors. phpinfo() run via IIS in a web page shows the same active/activated cURL as in php.exe -i. My libeay.dll and ssleay.dll libraries are all over my path.
There doesn't seem to be a problem with cURL itself. My best guess is that this is a firewall thing or a permissions thing, where IIS runs PHP as a guest user who is blocked from network access, but when I run it from the commandline, I'm not blocked.
I don't know enough about configuring IIS or the firewall or security policies to figure out where to change things and I don't want to accidentally open up a big hacker tunnel into my system by just randomly lowering security until something clicks. Please help.
"Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: No such host is known".
That's your clue, No such host is known, try a raw IP address see if that works, if so then it's because PHP can't see hosts basically IIS isn't passing that info in perhaps.

Categories