Here is my connection code, I have made mysql database in 000webhost and I have also uploaded file in 000webhost but every time I am getting error like this "
PHP Error Message
Warning: mysql_connect() [function.mysql-connect]: Access denied for
user 'a1346052'#'10.1.1.39' (using password: YES) in
/home/a1346052/public_html/connection.php on line 7
Free Web Hosting
Could not connect database
please help me on this, Thanks
<?php
$mysql_hostname = "mysql13.000webhost.com";
$mysql_user = "a1346052";
$mysql_password = "*****";
$mysql_database = "a1346052_simple";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?
I dont think your username will only be that. There will certainly be a username along with the random number. Ex: a7238414_username. Try running following code and see what result it gives.
$dbhost = 'mysql13.000webhost.com';
$dbuser = 'a7238414_username';
$dbpass = '***';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
Just a headsup, mysql is deprecated. You should start using mysqli or PDO :)
Related
I have an issue with PHP script not connecting to MySQL database. Below code always generates error:
$dbconn = #mysql_connect('SFDC1', '<username>', '<password>');
if (!$dbconn)
{
die('Error connecting to DB!');
}
There is no issue if I connect to the database using MySQL workbench with same credentials. Issue only occurs during the communication between PHP and MySQL.
Any help on debug of this issue?
Try this one;
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "pass";
$dbname = "DBname";
if(!#mysql_connect($dbhost,$dbuser,$dbpass)) {
echo "Cannot connect";
die();
} else
mysql_select_db($dbname);// or report();
Use this code to connect mysql.
<?php
$dbconn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$dbconn ) {
die('Could not connect: ' . mysql_error());
}
?>
I'm obviously new to PHP, and I've been asked by a friend to create a dynamic blog that could use continuously. I wanted it to connect to phpMyAdmin so it would be easier, but when I try to connect with it to my web page, it always fails and my set error appears. I don't know what to look up to help me. I'm sorry if I'm not clear. Post if you want me to go more into detail.
Here's my code:
<?php
$dbhost = 'localhost';
$dbuser = ' root';
$dbpass = '';
$dbname = 'blog1';
$connect = mysqli_connect($dbname, $dbuser, $dbhost, $dbpass) or die ('Cannot connect to database.');
echo "Succesfully connected to database!";
?>
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root123';
$dbname = 'mydb';
$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Cannot connect to database.');
If you run PHPMyAdmin on localhost uncomment in file:
sudo gedit /etc/php5/apache2/php.ini
this line: mysqli.allow_local_infile = On
Restart Apache:
sudo /etc/init.d/apache2 restart or sudo service apache2 restart
Test This
<?php
$dbhost = 'localhost';
$dbuser = ' root';
$dbpass = '';
$dbname = 'blog1';
$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname) or die ('Cannot connect to database.');
echo "Succesfully connected to database!";
The mysqli_connect() was called in wrong way.
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
I have the following sqlconnection.php
$mysqli = new mysqli('localhost', 'myuser', 'mypassword', 'mydb');
if ($mysqli->connect_error()) {
die('Connect Error (' . $mysqli->connect_rror() . ') '
. mysqli_connect_error());
}
with myuser, mypassword and mydb values being set correctly.
Anyway, although I am able to do operations with phpmyadmin (I got that installed aswell) I can't get to connect to the database. Any idea on why and what exactly I should put in localhost?
Just try this way~
$dbhost = 'localhost';
$dbuser = 'dbuser';
$dbpass = 'password';
$dbname = 'dbname';
$link = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);
if all your db information is correct, should be working
I have created an html form (demo.html) & POST it's value to a php file (demo1.php). Then i created database in MySQL & wrote connection code in the php file (demo1.php) but it gives the following error
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'#'localhost' (using password: YES) in C:\xampp\htdocs\demo1.php on line 8
Error connecting to mysql
<?php
// contact to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
//$conn = mysql_connect("localhost","root","password") or die ('Error connecting to mysql');
$dbname = 'test';
mysql_select_db($dbname,$conn);
//$connect = mysql_connect("localhost", "root", "pass") or die ("Error , check your server connection.");
//mysql_select_db("test");
//Get data in local variable
$v_name=$_POST['name'];
$v_email=$_POST['email'];
$v_msg=$_POST['msg'];
// check for null values
if ($v_name=="" or $v_msg=="")
echo "All fields must be entered, hit back button and re-enter information";
else{
$query="insert into contact(name,email,msg) values('$v_name','$v_email','$v_msg')";
mysql_query($query) or die(mysql_error());
echo "Your message has been received";
mysql_close($conn);
}
?>
Password for user root is incorrect.
Default password on local (home) server is empty, so I think this can help:
$dbpass = '';
The error is pretty explicit - the username/password combination youre using is incorrect. IF thisis a fresh install you need to set a password and/or create a new user.
mysqladmin
User Creation
Granting Privileges
Setting Passwords
For Local Xampp username-root password --''
<?php
// contact to database
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
?>
The main reason for this is that the password is wrong. Did you specify the root password when setting up xampp? If not, then leave the password blank as delphist states above