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

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?

Related

how to access my database in cpanel server?

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

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 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.

create database if not exists php mysql

I'm trying to create a database if it does not exist. Code is here:
<?php
// Connect to MySQL
$link = mysql_connect('host', 'user', 'pw');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Make studentdb the current database
$db_selected = mysql_select_db('StudentDB', $link);
if (!$db_selected) {
// If we couldn't, then it either doesn't exist, or we can't see it.
$sql = 'CREATE DATABASE StudentDB';
if (mysql_query($sql, $link)) {
echo "Database StudentDB created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
}
mysql_close($link);
?>
I'm getting this error:
Error creating database: Access denied for user 'myusernamehere' to database 'StudentDB'
the user has dba permissions...I'm guessing this is a permission error for my user....how can I give the user permission through the script and make this script work?
the users you are trying to use have no priviledges to use CREATE
try to switch to another user that have all the priviledges needed on manipulting the database or
add the needed priviledges to the user you are using
it happend to me and the following solved the problem:
first before using code to editing the database go to the main
localhost/index.php page then choose phpMyAdmin database manager
after than make sure that you are loged in as admin

Connecting to a mysql Database via PHP?

Ok, Ive been playing around with PHP and databases. Note, Im doing all my work on a webserver hosted by bluehost.
So I went into the cpanel and set up a database called gagalugc_stocks.
I also setup a username (test) and a password (password) and added them to be able to control the databse. Below is my script in an attempt to connect to it, not it is also on the server.
<?php
$connect = mysql_connect('localhost','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)
?>
-Thanks
NOTE: The problem is that it can never reach the database.
<?php
$connection = mysql_connect ('localhost', 'test', 'password')
or die ('<b>Could not connect: </b>' . mysql_error());
$result = mysql_select_db("gagalugc_stocks")
or die ('<b>Could not connect: </b>' . mysql_error());
?>
Didn't check for port when adding database make sure to specify host and port
(localhost:2083)
How about
<?php
$connect = mysql_connect('localhost:2083','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)
?>
For local system:-
$con = mysql_connect("localhost","root","");
if (!$con){
die('Unable to connect to the server ' . mysql_error());
}
mysql_select_db("databasename", $con) or die(mysql_error());
For website or remote server:-
$con = mysql_connect("localhost","username","password");
if (!$con){
die('Unable to connect to the server ' . mysql_error());
}
mysql_select_db("databasename", $con) or die(mysql_error());
for more please visit : Algosoftwares

Categories