I want to connect 2 diffrent DB, but I get that error:
Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user '*username*'#'localhost' (using password: YES) in......
my code:
$mysqli2 = new mysqli('localhost',$db_user,$db_pass, $db_name);
$mysqli2 = new mysqli('localhost',$db_user2,$db_pass2, $db_name2);
And I try to excute queries like this:
$result=$mysqli->query("select ......
$result=$mysqli2->query("select ......
How can I fix this?
Your username or password is wrong.
Your mysql user may not have the right privileges to connect over the network.
See here : How to grant remote access permissions to mysql server for user?
check password and adress and username
use next code to connect
$connect1 = new mysqli(...);
$connect2 = new mysqli()
if ($connect1->connect_error)
echo "error in 1 connection message: " . $connect1->connect_error;
if ($connect2->connect_error)
echo "error in 2 connection message: " . $connect2->connect_error;
where you see a problem ?
Related
I am trying to install my php script on live server but am getting an error. I have already created a db/user and uploaded sql to my phypmyadmin
Error I am getting is
Access denied for user 'user'#'localhost' (using password: YES)
It's simply telling you that the username or password is not right, so you can't have an access.
Please check the password and the name of the user inside your php script, take a look at this.
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
?>
You see in your case you need to change these parameters to the ones in your live server.
$con = mysqli_connect("your_server","your_user","your_password","your_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
I am attempting to retrieve some data from my database, I appear to be able to connect to the database as I do not get an error message after the connection is tested. But when I attempt to run a select query, it causes an internal error.
If I take the FROM part away from the query, the page loads with no data. If I add the FROM part back in, with the table to be selected from, the internal error occurs.
The code is below:
$con = mysqli_connect("50.62.209.87:3306","myusername","mypassword",
"FiveExtras");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$query = "SELECT `EventVenue`,`EventDate`,`EventTime`,
`EventPostCode` FROM `event`";
$result = mysqli_query($con, $query);
$row = $result;
echo $row;
Rewrite your connection:
$db_conn = mysqli_connect("$host", "$dbuser", "$dbpass") or die("Unable to connect to the database");
mysql_select_db("$dbase", $db_conn) or die("Unable to select the database");
$query = mysqli_query("SELECT `EventVenue`,`EventDate`,`EventTime`,
`EventPostCode` FROM `event`");
And why $result = $row ?
EDIT: For a better query , use "SELECT * ... "
did you change your htacess? Changes to .htacess often cause internal server error. or your host ip is bad(try no-ip.com, they give free subdomains for your ip's)
i checked it with removed port it worked(well...not connecting but no error about host), so maybe it's something to do with port
if error 500 remains try get support ticket or email webmaster or get another hosting provider
why would you say no error?
here we go:
Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given
in /home/u451361813/public_html/test.php on line 13
and
Warning: mysqli_connect(): (28000/1045): Access denied for user
'myusername'#'185.28.20.221' (using password: YES) in /home/u451361813
/public_html/test.php on line 3
Failed to connect to MySQL: Access denied for user
'myusername'#'185.28.20.221' (using password: YES)
1st one is for no information returned second for no password
I have a database and database user created via cpanel as below:
database name: test_database
database user: test_user
I am trying to connect to this database on the same server via a php script below:
<?php
$servername = "localhost";
$username = "test_user_test_database";
$password = "test";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
However I end up with:
Warning: mysqli_connect(): (28000/1045): Access denied for user 'test_user_test_database'#'localhost' (using password: YES) in /home/driver/public_html/login/connect.php on line 7
Connection failed: Access denied for user 'test_user_test_database'#'localhost' (using password: YES)
Is the issue down to having an underscore in the username and database name? Or is there a way round this? I would much rather keep the username and database name as they are so wanted to check if there is any other way round it
Underscores are fine for naming.
mysqli_connect takes the database name as the 4th argument. Try adding your database name.
Finally, I seem to remember cPanel using some sort of automatic prefixes or something... double-check your database credentials if it's still not working.
You'll also have to add the user and the user permissions on that database.
The code is:
$mysql = new mysqli('10.1.36.20', 'user', 'password', 'dbname');
The result is:
Warning: mysqli::mysqli(): (28000/1045): Access denied for user 'user'#'10.1.36.111' (using password: YES) in ....
webserver IP: 10.1.36.13;
mysql server IP: 10.1.36.20
where did it got 10.1.36.111?
I was tried through mysql_connect - The same problem.
The fastest fix is to look at the error and read it. For example, if "(using password: NO)", then you need to make sure your connection is using a password.
If "(using password: YES)", then make sure you are using the correct password.
If the error reports
Couldn't connect :
localhost: Connection error to server 'localhost' with user 'username_user'
Make sure you have added the user to the database and granted permissions to this user.
or
Create a new user or use proper username and password for the database
for managing this go to your Phpmyadmin->User->Add user
Default:
username:"root"
password:""
And use this function for reference.
<?php
// db connect to nm database
function db_connect_nm()
{
//Database server
$host= 'localhost';
$nm_name= 'myname_databasename';
$nm_user= 'myname_dbusername';
$nm_pword= 'password';
$nm_connect = new mysqli($host, $nm_user, $nm_pword, $nm_name);
if (!$nm_connect)
throw new Exception('Could not connect to NM database ');
else
return $nm_connect;
}
?>
9 out of 10 PHP problems can be resolved by setting so please check that too
I'm trying to create a very simple create account page. This is the part of the MySQL Database connection:
<?php
function dbconnect()
{
$connection = mysqli_connect("localhost","maistral_quizonline","maistral_kalkas","abcdefghi");
if (mysqli_connect_errno($connection))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return 0;
}
return $connection;
}?>
When I try to run dbconnect this is what I get as output:
"Failed to connect to MySQL: Access denied for user 'maistral_quizonl'#'localhost' (using password: YES)Access denied for user 'maistral'#'localhost' (using password: NO)"
Now, I'm new to php and maybe i do something really silly, can anyone explain to me this output? Why it seems to try for connection twice and why the connection information is corrupted? What is this: maistral_quizonl? maistral? Why is it cutting the words? And why the first time says that I'm using password and the second time says no? I hope my mistake is not so stupid.
And one other thing. I saw in another post someone suggesting to check if the mysqli_connect function exists so I change this:
echo "Failed to connect to MySQL: " . mysqli_connect_error();
to this:
echo "Failed to connect to MySQL: " . mysqli_connect_error() . var_dump(function_exists('mysqli_connect'));
and the output was this:
"bool(true) Failed to connect to MySQL: Access denied for user 'maistral_quizonl'#'localhost' (using password: YES)Access denied for user 'maistral'#'localhost' (using password: NO)"
lol?
I know that it's pointless to check if mysqli_connect exists after you use it but am I mistaken or isn't the "bool(true)" suppose to print at the and of the line and not the beggining?
What is going on?
Thank you
PS: I have double check that the database exists as well as the user and the priviliges and the password
mysqli_connect accepts parameters in this order 'host', 'username', 'password', and 'dbname', is this the order in which you have provided your details? It does not seem so.
http://us2.php.net/manual/en/mysqli.construct.php