CodeIgniter database error when opening the website - php

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

Related

CodeIgniter Database Error but only one section of app

I have an existing web app but for no apparent reason one section of the app is now displaying the following error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338
The rest of the app works fine and can connect using the same database credentials at application/config/database.php
Any help to point me in the right direction in terms of debugging the issue would be welcome.
This is for an existing Linux server, running MySQL 5, PHP 7 and Apache 2.
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 338

MariaDB local access error (remote access fine)

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.

How can I set a web server directory for an extension_dir in php.ini?

Currently I am doing a web based PHP project which is connected with SQL Server with sqlsrv method in php. The frame work is CI, and I use php_pdo_sqlsrv_56_ts.dll extension to connect the SQL Server like (extension=php_pdo_sqlsrv_56_ts.dll) in php.ini. It works in my local client without any issue.
But I needed to host the web site in my shared web server, the SQL Server is already connect with an IP address.
How can I do this?
I tried in below method, but it gives error:
method 01
I uploaded all the dll files in web server and I changed the extension_dir as
extension_dir=http://example.uk/myweb/sqlsrv_dll_files/
method 02
I uploaded all the dll files in web server and I set the extension path as
extension=http://example.uk/myweb/sqlsrv_dll/php_pdo_sqlsrv_56_ts.dll
But this gives below error:
Fatal error: Call to undefined function sqlsrv_connect() in C:\xampp_v5\htdocs\web_project\system\database\drivers\sqlsrv\sqlsrv_driver.php on line 144
A PHP Error was encountered
Severity: Error
Message: Call to undefined function sqlsrv_connect()
Filename: sqlsrv/sqlsrv_driver.php
Line Number: 144
Backtrace:
Please advice me to rectify this error.
Thanks in advance,

Ubuntu/Drupal: PHP can not connect to other MsSQL Server

I copied one of our test servers and now I'm having a weird issue.
We have 2 MsSQL-servers, but I can only connect to one of them. I can not find any configuration issues that should cause this and other test server can connect to both fine. Any tips what could cause the issue and where to look?
The only clue is this in Drush logs:
2744375 11/Mar 12:46 php warning Warning: mssql_connect(): Unable to connect to server: MY.SQL.SERVER in eval() (line 4 of /srv/drupal/modules/php/php.module(80) : eval()'d code).

Transfer testing server files to live server and avoid errors

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.

Categories