I compiled PHP with mysqlnd using the prescriptions from Mysqlnd installation. PHP works fine. php -m | grep mysql shows that neccessary MySQL modules are actually installed. Then I run php -S localhost:8088 -t <dir>. In PHP code function_exists('mysqli_connect') does return true. But when I run mysqli_connect() warning mysqli_connect(): (HY000/2002): No such file or directory arises. In /etc/php.ini I set default socket to /tmp/mysql.sock then to /var/lib/mysql/mysql.sock. Both variants didn't work. How can I enable mysql support in PHP-built-in server?
Have you tried those solutions ?
Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in
First try to use 127.0.0.1 instead of "localhost" in your mysqli_connect call.
Then make sure there is sockets where it should : make a symbolic link from /tmp/mysql.sock to /var/mysql/mysql.sock (or other way depending what exists on your computer)
Finally try to read all answers listed in the link above, maybe one of them will hel you
Related
My working index.php that runs in a browser looks like this:
<?php
$dbh = new PDO(...whatever
It works in a bowser just fine. I can do anything.
Running in terminal like:
shell> php index.php
I get some error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] No such file or directory' in /Library/WebServer/Documents/index.php:3
Stack trace:
#0 /Library/WebServer/Documents/index.php(3): PDO->__construct('mysql:host=loca...', 'root', 'frekinpassword')
#1 {main}
thrown in /Library/WebServer/Documents/index.php on line 3
What's going on here?
I think, your unix_socket changed and you didn't change your php client php.ini
First of all, get your unix_socket location.
$ mysql -uroot -p
Enter your mysql password and login your mysql server from command line.
mysql> show variables like '%sock%';
+---------------+---------------------------------------+
| Variable_name | Value |
+---------------+---------------------------------------+
| socket | /opt/local/var/run/mysql5/mysqld.sock |
+---------------+---------------------------------------+
Your unix_soket could be diffrent.
Then change your php.ini, find your php.ini file from
<? phpinfo();
You maybe install many php with different version, so please don't assume your php.ini file location, get it from your 'phpinfo';
Change your php.ini:
mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket = /opt/local/var/run/mysql5/mysqld.sock
pdo_mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
Then restart your apache or php-fpm.
It looks like you're using localhost as the connection string for your MySQL database. When MySQL sees localhost, it interprets that as "use a mysql.sock" file. PHP is telling you it can't find that mysql.sock file.
The most likely cause for this is your web server and command line PHP are configured to use different php.ini files, and those php.ini files have differently configured mysql.sock files. You can find your web server php.ini file(s) by running
phpinfo();
from a PHP file loaded via the web server. You can find your command line php.ini file(s) by running the following
$ php --ini
If you can't fix your command line php.ini file, consider connecting to your MySQL server via 127.0.0.1 instead of localhost. When you use the IP address, PHP should attempt to connect via the network instead of a socket file.
got some space at an intern SUSE Linux Enterprise Server 11 (x86_64) for the apache-webserver (apache 2.2.29, php 5.4.40) of our department.
Our php is built with Oracle, not MySQL. I wanna install MySQL additionally but due to our very strict guidelines I only have permissions to write in my "/usd/[user]"-directory, not "/var/lib" etc. so there is no possibility to run the command "rpm -i MySQL-server-5.6.25-1.sles11.x86_64.rpm" or sth like that.
user:/usd/as07100a/soft> rpm -i MySQL-server*
error: can't create transaction lock on /var/lib/rpm/__db.000
user:/usd/as07100a/soft> touch /var/lib/rpm/__db.000
touch: cannot touch `/var/lib/rpm/__db.000': Permission denied
Is there any known option I can install MySQL with my restricted permissions (e. g. kinda portable version)?
It seems that this is possible:
Install MySql without root access
Also see this post for additional configuration information: Mysql - specify socket location
You will also likely need to change the port number in your configuration since OracleSQL is probably running on that port already. You can use netstat to see if any other program is listening on 3306.
netstat -ntl
I have installed XAMPP on my Ubuntu 14.0.04 and I'm trying to connect to my MySQL server from PHP file but I'm getting an error:
Warning: mysql_connect(): No such file or directory in /opt/lampp/htdocs/value.php on
line 3
not connected
my value.php file contains
<?php
$con = mysql_connect('localhost:3307', 'root', '');
if ($con) echo 'Connected';
else echo 'not connected';
---
?>
and my MySQL server is up and running and my server is also running.
Which version of mysql are you using?
Try this
127.0.0.1:your-port-number
like
$con = mysql_connect('127.0.0.1:3307', 'root', ''); // or 3306 whatever your port number is
instead of localhost
I too had this problem, but this link helped me Warning: mysql_connect()
It looks like mysql has got the location of the socket file wrong; and it can be fixed by simply setting the symbolic link to correct it.
The socket file (zero length file) will be either be available in /tmp/mysql.sock or /var/mysql/mysql.sock. Depending on which one is missing create a symbolic link for other.
cd /var
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
ln -s /tmp/mysql.sock mysql.sock
If I run
php -r 'print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));'
I get "Tue Oct 28 13:24:01 UTC 2014" (as expected).
But if I have a php file:
<?php
print_r(file_get_contents("http://mirror.facebook.net/centos/timestamp.txt"));
It gives me:
**Warning:** file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known ...
**Warning:** file_get_contents(http://mirror.facebook.net/centos/timestamp.txt): failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known ...
What is the difference between "php -r" and php running the code out of a file
UPDATE
This is not the answer to the question but it did solve my problem so for the sake of future googlers: I don't know which of these two solutions was the key but it was working when I restarted apache.
In resolv.conf set nameserver 8.8.8.8 (which had my router's address)
There's an SELinux boolean httpd_can_network_connect which must be turned on:
setsebool -P httpd_can_network_connect 1
See this solution and this one.
Your PHP CLI is using a different php.ini (or maybe no php.ini at all). It's also possible you are running a completely different PHP binary than what your server is using.
You can run php -i on the command line, and phpinfo() in a script to determine which php.ini is in use.
I am trying to connect to a mssql db with dblib using the IP of the server as the host in the DSN.
With tsql, this works without any problem
$ tsql -S 192.168.56.101 -U .\user -P user
but in PHP this does not work.
$pdo = new PDO("dblib:host=192.168.56.101,1433;dbname=OtherC", '.\user', 'user');
The error I get is :
Error : SQLSTATE[01002] Adaptive Server connection failed (severity 9)
Check these:
port separator is "," on windows and ":" on linux/Mac
I never saw username as '.\user' but 'user'
locate freetds.conf on your disk. It is possible it exists in several places and tsql uses one while PHP used another one. Best is to symlink them into one common file and test on that. Note that a common place for that file is ~/.freetds.conf beside /etc/ or /usr/local/etc/
there should be a [global] section on your freetds.conf file. Put there these lines :
tds version = 8.0
text size = 20971520
client charset = UTF-8