Error establishing a database conection - php

While trying install wordpress i recieve following error
I use wampserver i have changed wp-config.php file and now it looks like this:
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', 'root');
/** MySQL hostname */
define('DB_HOST', 'localhost');//i used 127.0.0.1 too but no matter
define('WP_DEBUG', true);
wp-db.php file:
1379 line:
mysqli_real_connect( $this->dbh, $host, $this->dbuser, $this->dbpassword, null, $port, $socket, $client_flags );
1409 line:
$this->dbh = mysqli_connect( $this->dbhost, $this->dbuser, $this->dbpassword, $new_link, $client_flags );
but still no result I do not know what to do can anyone help me?

if you are using default configuration of xampp/wamp try with
define('DB_PASSWORD', ''); // for localhost
generally localhost db config:-
host = localhost
user = root
password = '' (blank)

Is root really the MySQL user you want to connect as? Is root its password?
It's usually not necessary and from a security standpoint potentially very dangerous to let web applications use your MySQL root user. Create a new user for your WordPress instance, give it its own database:
CREATE DATABASE wordpress;
GRANT ALL PRIVILEGES ON wordpress.* TO blog#localhost IDENTIFIED BY '3AmAbsKCsrKDw':
Then use that user
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'blog');
/** MySQL database password */
define('DB_PASSWORD', '3AmAbsKCsrKDw');
/** MySQL hostname */
define('DB_HOST', 'localhost');
define('WP_DEBUG', true);
That should let you connect. Verify that you can connect with those login credentials before continuing to your WordPress setup. WAMP includes a phpMyAdmin interface as far as I know, so try those credentials there.

Update your wp-config.php file like this
define your database name when you create on your localhost or server
define('DB_NAME', 'Your database name');
Ex:- You create your database name like "wordpress" then put database name like
define('DB_NAME', 'wordpress');
If you run your project in local always put root and when you upload database in your server you put your database user name when you create database
define('DB_USER', 'root');
Put your password when you create database on server other wise you can put ''
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');
define('WP_DEBUG', true);

Related

How do I use my host server info instead of localhost on XAMPP?

I have been building a website with PHP functionality in XAMPP, and everything works perfectly within the localhost. Although, I know that in order to have the same functionality on a live hosted server I will need to change the server info in my config.php file that is used:
<?php
define('ROOT_URL', 'http://localhost/newkellumws/');
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'austink01');
define('DB_NAME', 'kellumws');
I've tried changing the DB_HOST to my hosting profile's nameserver, but that did not work. Any help is much appreciated and thank you for your time. I apologize if the is a newbie question...
Assuming you are also moving the site as well the hostname will remain as localhost (as is the case with most shared hosting)
Assuming it's cPanel hosting you will first need to create the database.
You can then create an SQL account and grant it access to the DB (recommended) or use your cPanel credentials (Not Recommended)
So your config would look something like this:
define('ROOT_URL', 'http://example.com/newkellumws/');
define('DB_HOST', 'localhost'); // Website and SQL ruinning on the same server
define('DB_USER', 'exampl_kellumws');
define('DB_PASS', 'aBc*63oie8wfq');
define('DB_NAME', 'exampl_kellumws');
See https://documentation.cpanel.net/display/68Docs/MySQL+Databases
if the site is still going to be run via XAMPP (For whatever reason) you would also need to allow Remote MySQL
See https://documentation.cpanel.net/display/68Docs/Remote+MySQL
So your config would instead look something like this:
define('ROOT_URL', 'http://example.com/newkellumws/');
define('DB_HOST', 'c01.example.host'); //Address the SQL Server
define('DB_USER', 'exampl_kellumws');
define('DB_PASS', 'aBc*63oie8wfq');
define('DB_NAME', 'exampl_kellumws');
If you still have issues, contact your hosting provider as they will know the server setup and requirements.
You can also create testConnection.php with the following to help diagnose errors
<?php
require_once('path/to/file/with/config.php');
//Step-1 : Create a database connection
$connection=mysql_connect(DB_HOST,DB_USER,DB_PASS);
if(!$connection) {
die(“Database Connection error: ” . mysql_error());
}
//Step-2 : Select a database to use
$db=mysql_select_db(DB_NAME,$connection);
if(!$db) {
die(“Database Selection error” . mysql_error());
}
echo('Connected to Database');
Your server infos and local XAMP are different localhost works like following.
You dont need url part as its localhost/your_folder
<?php
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', ''); //Xamp doesnt have a password for root as default leave it empty if you didnt set one.
define('DB_NAME', 'kellumws');
define('PORT', '3306');
latest version of XAMP request port for MySql port, add it into your connection. mostly its 3306 as default but sometimes it changes to 3307 or 3308 because of mariaDB comes as default you can see real path on XAMP tool.
Than just call http://localhost/newkellumws/ if you created a folder.

Error establishing a database connection in my localhost

I am trying to install Wordpress in my localhost Xampp server
But every time I got an error message with
error establishing database connection.
This either means that the username and password information in your
wp-config.php file is incorrect or we can’t contact the database
server at localhost. This could mean your host’s database server is
down.
I have already googling but not get the correct answer yet.
I add define( 'WP_ALLOW_REPAIR', true ); in wp-config.php but not solved.......
This means wordpress can't find your database.
Navigate to http://localhost/phpmyadmin. Where it says create new database, choose a name for your database.
Next, open up wp-config.php in the root of your wordpress folder, and update the four values shown below to reflect your new database.
The default credentials for your newly created database are:
DB_NAME: Your chosen db name (case sensitive)
DB_USERNAME: root
DB_PASSWORD: ""
DB_HOST: localhost
/** The name of the database for WordPress */
define('DB_NAME', 'case sensitive chosen db name');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
I have solved my error as below procedure.
While installing Wordpress in localhost, first set some credentials of the file wp-config-sample.php as below
/** The name of the database for WordPress */
define( 'DB_NAME', 'learn_wordpress' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', '' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
and save the file name as wp-config.php and run again localhost/wordpress in the url.
It's done !!

Trouble Deploying Wordpress Using GAE - Locally Runs Properly

I properly set up the Cloud SQL instance and wordpress runs properly locally.
When I try to run the following commands, where INSTANCE_IP is my IP address to my Cloud SQL instance I get an error in my syntax:
{PATH_TO_MYSQL_BIN}/mysql --host=INSTANCE_IP --user=root --password
create database wordpress_db;
exit;
Edit, Error Message:
{PATH_TO_MYSQL_BIN}/mysql --host=xxx.19x.2xx.xx --user=root --password -> create database wordpress_db; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{PATH_TO_MYSQL_BIN}/mysql --host=173.194.243.33 --user=root --password create da' at line 1
If anyone could tell me what is wrong with my syntax that would be great, thanks in advance.
The following is the wp-config.php I believe is relevant:
// Required for batcache use
define('WP_CACHE', true);
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress_db');
/** MySQL database username */
define('DB_USER', 'root');
if (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'],'Google App Engine') !== false) {
/** Live environment Cloud SQL login and SITE_URL info */
define('DB_HOST', ':/cloudsql/your-project-id:wordpress');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
} else {
/** Local environment MySQL login info */
define('DB_HOST', '127.0.0.1');
define('DB_USER', 'root');
define('DB_PASSWORD', 'password');
}
// Determine HTTP or HTTPS, then set WP_SITEURL and WP_HOME
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443)
{
$protocol_to_use = 'https://';
} else {
$protocol_to_use = 'http://';
}
define( 'WP_SITEURL', $protocol_to_use . $_SERVER['HTTP_HOST']);
define( 'WP_HOME', $protocol_to_use . $_SERVER['HTTP_HOST']);
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
looks like you're following a guide from the Google cloud project site.
Here's some solutions:
First, if you have altered the user name or password during mysql install, make sure you update that in the config.php for wordpress.
Here's the thing - in MySQL, if you are using the Workbench then all you need to run is:
create database wordpress_db;
As the other script was if you're running it from cmd tool I believe.

wordpress on xampp database error

Hi I am trying to install worpress on xampp to design and test my blog on but when I go to localhost/wordpress it keeps telling me that
"Error establishing a database connection"
Please help been trying everything.
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'root');
/** MySQL database password */
define('DB_PASSWORD', '');
/** MySQL hostname */
define('DB_HOST', 'localhost');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');
I am running it on Windows XP
Try create Wordpress database on your MySQL server
The error message would suggest that the details you have in your code sample are incorrect.
Do you have a 'wordpress' table?
Can you log into phpMyAdmin using the XAMPP suite using the account 'root' without a password?
You may need to setup a new user account with a password and grant the relevant privileges and then re-install Wordpress.

Problem to connect on MySql database on the remote server

I have been developing my php mysql application locally and it worked fine with this connection parameters:
// Database connection params
define('HOST', 'localhost');
define('USERNAME', 'root');
define('PASSWORD', '');
define('DATABASE', 'some_db');
at some point I wanted to put application online with connection parameters:
define('HOST', 'somedomain.com');
define('USERNAME', 'some_db_admin');
define('PASSWORD', 'Password1!');
define('DATABASE', 'some_db');
When I try to connect to remote database like this:
function db_connect()
{
$connection = #mysql_connect(HOST, USERNAME, PASSWORD);
if(!$connection)
{
return false;
}
if(!mysql_select_db(DATABASE))
{
return false;
}
return $connection;
}
I get error:
Access denied for user 'some_db'#'localhost' (using password: NO)
How can it possibly be localhost?
I have regularly created database and user that database using using database wizard in cpanel.
What can be the problem?
Thanks a lot!
If your PHP code is at the same host where the MySQL database is then setting HOST to localhost should solve your problem
define('HOST', 'localhost');
It also seems that you swapped your constants, because some_db is not likely to be a user but rather a database. Try debugging and output the constants' values just before the 'mysql_connect' call.
If this does not work, try debug_backtrace().

Categories