I am aware that transferring files from local/testing servers to a live site server is a pretty cut-and-dry process. However, I have had several issues with the one site that I am working on for a client.
The site is using a mysql database for much of the information and images supplied since it is a retail-based business with thousands of patterns/swatches to choose from. All of my files transferred perfectly to testing and work correctly. However, when I in-turn push the files live, I receive the following error messages:
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/warner_walls/warnerwalls.com/advsearch.php on line 133
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/warner_walls/warnerwalls.com/advsearch.php on line 133
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/warner_walls/warnerwalls.com/advsearch.php on line 134
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /home/warner_walls/warnerwalls.com/advsearch.php on line 148
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/warner_walls/warnerwalls.com/advsearch.php on line 148
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/warner_walls/warnerwalls.com/advsearch.php on line 241
Please note that the database connection is the same for both the test server and live server; which is why I cannot figure out why it works on one and not the other. I have used the program, TextWrangler to compare all php pages in question to find differences in the code that may be causing the error and all pages are marked to be identical.
The images that are being requested in the search, when the error messages appear, are displayed correctly, it is just the error statements are overlapping the last line of swatches and stacked under from there.
What should I be looking for to help correct this?
The first error message is quite clear:
Warning: mysql_query() [function.mysql-query]: Can't connect to local
MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in
/home/warner_walls/warnerwalls.com/advsearch.php on line 133
Of course, the local MySQL server is running?
It is configured to listen for local connection on the unix socket? (check in /etc/my.cnf for the line socket=/var/run/mysqld/mysqld.sock)
If you have copied all the DB files from the live server to your test platform, I assume you have copied the mysql DB files too (those that store user tables, permissions and so on).
That would be confirmed when you say "that the database connection is the same for both the test server and live server".
If that analysis is not totally completely stupid, my guess would be the DB is configured to grant permissions to user#ip_address or user#% -- but not to user#localhost.
Related
I keep on getting this error I dont know when it started. Sometimes my program runs without that error sometimes it has this error. Please help!!
I have uploaded file same as this one with error but when i look at the webpage it is running smoothly
I tried changing ports and restarting my wamp but it doesnt get any better
Warning: mysql_select_db(): Error while reading INIT_DB's OK packet. PID=8808
Warning: mysql_select_db(): MySQL server has gone away in
connection on line 4
Line 4 ----> mysql_select_db('dbname')
I think Now will be fined;
mysqli_connect("localhost","root","password","dbname");
It seems most access issues have been remote, but this is the reverse problem.
Here are all the error messages:
PHP Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'root'#'10.168.101.35 (using password: YES) in /var/www/html/hamlookup/index.php on line 291
PHP Warning: main(): Couldn't fetch mysqli in /var/www/html/hamlookup/index.php on line 291
PHP Fatal error: Call to undefined method mysqli::fetch_fields() in /var/www/html/hamlookup/index.php on line 295
I have setup MariaDB on CentOS 7 with password and I can remotely access it from various Windows machines using any SQL client (php or apache not involved).
I can also access it using the mysql command line tool.
mysqli is enabled in php (I checked with phpinfo()).
However, I get these errors when I check my web page running "php index.php" at the console, and of course when the web page is accessed via apache it crashes there too.
The lines causing the error are (line numbers in square brackets):
[290] $mysqli = new mysqli( "10.168.101.35","root","*****","hamlookup" );
[291] if( $mysqli->error ){
[292] [calling error function here then exit]
[293] }
[294] $result = "SELECT * FROM mytable";
[295] $fieldinfo = $mysqli->fetch_fields( $result );
It seems like it's an issue between php, mysql and apache but I can't figure it out.
I have also tried to connect via PDO and I still cannot connect to the server.
This is ridiculous since I can connect via CLI and via the network, simply php is not able to access the database.
you need add the line in file /etc/my.cnf
[mysqld]
bind-address = 0.0.0.0
restart mysql
Problem solved...
I was checking $myDPO->errorInfo() to verify success incorrectly.
This was migrated from the old mysql_*** access API and it turns out that in fact I was accessing the database.
Once the errorInfo() check was changed, it seems like everything is working.
Sorry for the bandwidth.
The website works fine for a while but in a few days returns this error :
A PHP Error was encountered
Severity: Warning
Message: mysqli::real_connect(): (HY000/2002): Can't connect to local
MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Filename: mysqli/mysqli_driver.php
Line Number: 202
Backtrace:
File: /var/www/html/application/controllers/Login.php Line: 8
Function: database
File: /var/www/html/index.php Line: 289 Function: require_once
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/CodeIgniter.php
Line Number: 500
Help will be appreciated
Thanks
Nipun
Three things possible. Your database has been shut down (or it has died). You have not setup database to use a unix socket when both client and server are on the same machine. Or socket is not readable and writable by web user.
The warning is being thrown by mysqli driver. I would recommend that you use PDO driver to connect to the Database.It's simpler and a bit universal (You don't need to change Database settings once you change the DB)
you need confirm the database config file:application/config/database.php ensure the confirm item is correct
Please check your mysql server connectivity
If you run the app using your pc name i.e.
sahil-pc/recruitement or http://85.215.963.104:81/recruitement
you need to define it in index.php of root.
please check the permission of your db socket if you are using linux you need to make it in read and write mod.
note: ip details are fake don't try it
I'm running Moodle on PHP 5.5.7 64bit nts on Windows Server 2008 R2 with MySQL 5.5.36.
Up until two days ago, there were no problems. To deal with Xdebugger being such a memory hog, an extra CPU and more memory was assigned to the virtual machine. The Windows license was also activated. The entire vm was rebooted. (I had restarted the machine before prior to this, with no problems).
I am now receiving the following warning when I access any page on the site:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
in C:\inetpub\wwwroot\moodle\lib\dml\mysqli_native_moodle_database.php on line 375
I created a test php page that simply consists of the following:
$mysqli = new mysqli("127.0.0.1", "moodleuser", 'xxxx', "moodle", 3306);
if ($result = $mysqli->query("SELECT * from mdl_user limit 10")) {
echo "Select returned $result->num_rows";
} else {
echo "Error";
}
$mysqli->close();
I receive the following output:
PHP Warning: mysqli::mysqli(): (HY000/2002): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.in C:\inetpub\wwwroot\moodle\info.php on line 17
PHP Warning: mysqli::query(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 18
PHP Warning: mysqli::close(): Couldn't fetch mysqli in C:\inetpub\wwwroot\moodle\info.php on line 24
I have checked that "127.0.0.1 localhost" exists in my hosts file and that the IPv6 "::1" line has been commented out.
I have also attempted to use "localhost" but same problem.
The bizarre thing is that if I refresh the page, occasionally, and completely at random, the warning doesn't occur and the correct output is given.
I have attempted to disable the warnings, but php appears to be ignoring me. Also, disabling the warning is not exactly ideal.
Any ideas?
EDIT:
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.
So after much pain staking back and forths between PHP and MySQL and IIS, it looks like (once again) it was php.ini to blame.
To be honest, I cant even tell you which setting was the problem - but I changed all possible timeout related settings in php.ini to a large number (10000 or -1 depending on the setting), as well as the connection_timeout for mysql in my.ini.
I am still yet to figure out which one was causing the problem, but will edit this post if I ever do.
I have a LAMP website (PHP/MySQL), and I rely heavily on my MySQL database.
Recently, the following error started occurring intermittently:
[30-Oct-2011 16:11:49] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029
This is line 1029, the specific line that occasionally gives the above error:
$db = mysqli_connect($cfg['db_location'], $cfg['db_reader_username'], $cfg['db_reader_password']);
where $cfg['db_location'] is "localhost", and the username and password are correct.
It appears as though something is causing my PHP script to intermittently lose connection to the MySQL server, which is puzzling to me because all of my MySQL connections are made to localhost. That is, the PHP script and the MySQL server are both running on the same box, and I connect to MySQL via localhost.
Additionally, this is puzzling because my PHP script is able to successfully connect to the MySQL server for perhaps 90% of pages.
As best I can tell, my server has plenty of available RAM and CPU:
top - 16:38:23 up 173 days, 19:19, 2 users, load average: 0.57, 0.78, 0.84
Tasks: 142 total, 4 running, 137 sleeping, 0 stopped, 1 zombie
Cpu(s): 18.7%us, 27.5%sy, 0.7%ni, 52.6%id, 0.2%wa, 0.1%hi, 0.2%si, 0.0%st
Mem: 2976260k total, 1861368k used, 1114892k free, 532628k buffers
Swap: 2048248k total, 116k used, 2048132k free, 1035804k cached
And plenty of available disk space. When I run df -h, all of my filesystems are at most 25% in use.
So I don't know what would be causing the sporadic errors that I'm seeing in my PHP error logs.
Any ideas what might be causing my PHP script to intermittently lose connection to my MySQL server on localhost?
I upgraded to MySQL 5.1, and this is now what get when I run mysql -V:
mysql Ver 14.14 Distrib 5.1.56, for pc-linux-gnu (i686) using readline 5.1
The same errors are still happening, though:
[30-Oct-2011 20:26:18] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029
As before, the errors continue to be intermittent.
After I upgraded to MySQL 5.1, I've been looking carefully at my PHP errors logs. I've noticed a few other errors similar to the first one. For example, here's one such error:
[30-Oct-2011 22:42:29] PHP Warning: mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'reading authorization packet', system error: 104 in /home/path/to/my/code.php on line 1029
And here's another error I've seen in my logs:
PHP Warning: mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/path/to/different/code.php on line 7
In all cases, the problem fundamentally seems to be a failure to connect to MySQL. Any ideas what might be causing this or how I could debug it?
Perhaps this bug report will help - It seems that a fix may be to set a higher timeout for the global connect_timeout. It was set to a higher value in later versions of MySQL 5.1 (10 seconds) as opposed to 5 seconds for earlier versions.
http://bugs.mysql.com/bug.php?id=28359