Jump to content

Recommended Posts

I'm sure this is an obvious answer but I just can't find it. Mind you, it's one o'clock and I'm used to doing coding during the day, but what in the world am I missing? I know it's an obvious answer.

Error:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'virtuala_test'@'localhost' (using password: YES) in /home/virtuala/public_html/test/sql.php on line 10

 

sql.php:

 

<?php

$server = "localhost";
$db_user = "user";
$db_pass = "password";
$db_name = "name";

$con = mysql_connect($server, $db_user, $db_pass);

if (!$con) {
die ("An error has occured. Please contact the webmaster with the following error: " . mysql_error());
}

$con2 = mysql_select_db($db_name);

if (!$con2) {
die ("An error has occured. Please contact the webmaster with the following error: " . mysql_error());
}

?>

Link to comment
https://forums.phpfreaks.com/topic/242818-connection-error/
Share on other sites

you just giving yourself extra step in your connection. y not just

$con = mysql_connect('localhost', 'virtuala_test', 'password', 'dbname');
if(!$con)
{
  die ("An error has occured. Please contact the webmaster with the following error: " . mysql_error());
}

that will connect and select the database.

for the error, try to log into your database with the user n password you're gave in the connection. Most likely, u gave the wrong password, or the suer 'virtuala_test' is spelled wrong :) or it has not been granted access to the database you're trying to select to use...

oh and try my method of connection, you might have some lucks :)

talking about luck, good luck!!!

Link to comment
https://forums.phpfreaks.com/topic/242818-connection-error/#findComment-1247375
Share on other sites

you just giving yourself extra step in your connection. y not just

$con = mysql_connect('localhost', 'virtuala_test', 'password', 'dbname');
if(!$con)
{
  die ("An error has occured. Please contact the webmaster with the following error: " . mysql_error());
}

That wont work. mysql_connect doesn't have a fourth argument for selecting the database. You need to use mysql_select_db to connect to a database with the standard mysql function library.

Link to comment
https://forums.phpfreaks.com/topic/242818-connection-error/#findComment-1247412
Share on other sites

oopsi, i meant:

<?PHP
$con = mysqli_connect('localhost', 'virtuala_test', 'password', 'dbname')
?>

 

That will work so long as the OP is using the mysqli library functions within their code. The functions for mysql and mysqli are not interchangeable. So if you're using mysqli_connect toconnect to mysql but use mysql_query to run a query it wont work.

Link to comment
https://forums.phpfreaks.com/topic/242818-connection-error/#findComment-1247451
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.