how to access my database in cpanel server? - php

The following error occur for my website:
Warning: mysql_connect(): Access denied for user 'mydb_db'#'localhost'
(using password: YES) in
/home/fiveghr/public_html/don/dbconnection/connection.php on line 8
Could not connect: Access denied for user 'mydb_db'#'localhost' (using
password: YES)
<?php
$rpath = $_SERVER["DOCUMENT_ROOT"];
require $rpath."/don/dbconnection/config.php";
class getdbconnection {
public function getConnection(){
// $con = mysql_connect("localhost","*****","******");
$con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
if (!$con)
{
return die('Could not connect: ' . mysql_error());
} else {
// mysql_select_db("real_state", $con);
mysql_select_db(DB_NAME, $con);
//return $con;
}
}
}
?>

Value of DB_HOST
must be the server address as "http://www.myserver.com" not localhost

Related

cannot connect to server using php

<?php
$host="localhost";
$user="user";
$password="debashree";
$connect=mysqli_connect($host,$user,$password);
if ($connect->connect_error) {
die("connection_aborted".$connect->connect_error);
}
echo "connected succesfully";
This is the mysql connection php script. It is constantly showing the error of
Warning: mysqli_connect(): (HY000/1045): Access denied for user 'user'#'localhost' (using password: YES) in C:\xampp\htdocs\index.php on line 6
Notice: Trying to get property of non-object in C:\xampp\htdocs\index.php on line 7
connected successfully
I cannot understand please help me?
You should try the following changes made :
<?php
try{
$host="localhost";
$user="user";
$password="debashree";
$databaseName = "myDB";
$connect=mysqli_connect($host,$user,$password, $databaseName);
if (**mysqli_connect_errno()**)
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo "connected succesfully";
}catch(Exception $e){
echo $e->getMessage();
}
Also, mysqli_connect requires database as fourth parameter.
mysqli_connect("localhost","my_user","my_password","my_db");

db cant connect in php

I have a script where I need to connect to MySQL db. But somehow the connection is failed. Can anyone help me to check the problem? Thanks ahead.
$username = "root";
$password = "";
$hostname = "localhost";
$dbname = "vti_ctes_demo";
$con = mysql_connect($hostname, $username, $password);
if (!$con) {
die('Could not connect: ' . mysql_error());
}else
{
echo 'connected';
}
// make foo the current db
$db_selected = mysql_select_db($dbname, $con);
if (!$db_selected) {
die ('Can\'t use vti_ctes_demo : ' . mysql_error());
}else
{
echo 'connected';
}
The moment I run the query, I get this error:
Can't use vti_ctes_demo : Access denied for user ''#'localhost' to database 'vti_ctes_demo'
I have set the username as 'root', but it seems like it can't receive the username. Btw, first connection is successful. Just that, the moment when it's connected to the db, then the error appeared.
You need grant privileges to the user "root" if you want external access to database vti_ctes_demo.
Use this to grant permission to the user

Could not connect: Access denied for user 'indysoft_admin'#'localhost

ii have made a Mysql database and and user for the same with all permissions Still am getting the following error.
Could not connect: Access denied for user 'indysoft_admin'#'localhost
i am using the following connection.php script for connection
<?php
$con = mysql_connect('localhost', 'indysoft_admin','');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else{
mysql_select_db("indysoft_person", $con);
}
?>
You didnt create the User with the same credentials, like your passing. Check your Database for ur username and password. Maybe a misspelling?

Could not connect: Access denied for user 'root'#'localhost'

<?php
$name= $_POST["dbname"];
$pass= $_POST["dbpass"];
$rname= $_POST["rootname"];
$rpass=$_POST["rootpass"];
if ($rname='leave blank for default root name' or $name='')
{
$rname="root";
}
if ($rpass='leave blank if no password assigned')
{
$rpass='';
}
$con = mysql_connect("localhost", $rname, $rpass);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE {$name}",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
(mysql_query("DATABASEPASSWORD {$pass}",$con));
mysql_close($con);
?>
this is the php script i am using to create database,i am passing rootname=root and rootpass=toor
but i am getting an error
Warning: mysql_connect(): Access denied for user 'root'#'localhost'
(using password: NO) in /var/www/webdefender/script/dbcreate.php on
line 17 Could not connect: Access denied for user 'root'#'localhost'
(using password: NO)
but when i use
$con = mysql_connect("localhost", 'root','toor' );
it works fine
Please help
You're assigning values in your first 2 checks instead of checking them for equality.
$a = 1; // assigning
$a == 1; // this is a check if 1 is $a is equal to 1
So you're basically resetting your $rpass value to '' (empty string) in:
if ($rpass='leave blank if no password assigned')
{
$rpass='';
}
Change your checks to use == and it will work.
Please to be aware that using root access from scripts is a HUGE security hazard.
Don't use or use below code near if ($rname='')
if ($rname='')
{
$rname="root";
}
it's general when U use if like this
if($a=b)
always return true and $a have the value b
the right Syntax is
if($a==b)
so if and only if $a value = b it return true

Could not connect: Access denied for user php

I have an application written in C# and it does connect with the database.
Here's the error I'm getting:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'username'#'localhost' (using password: YES) in (php file) on line 15
Could not connect: Access denied for user 'username'#'localhost' (using password: YES)
Here is my code:
$mysql = mysql_connect("localhost", "username", "password");
if (!$mysql) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
I got this example from:
http://php.net/manual/en/function.mysql-connect.php
What am I doing wrong?
Your username in mysql in probably not "username", as your password is not "password". Please change it to something like
$mysql = mysql_connect("localhost", $username, $password);
where $username is variable with your db username and $password is variable with your db password.
Also it would be good thing to use MySQLi instead of mysql_ functions.

Categories