Hi, here I have another problem for you guys.I am doing this tutorial on mysql and php:
http://repository.ui.ac.id/dokumen/lihat/3322.pd

Now after I have reinstalled everything, MySql,phpMyAdmin and PHP everything works fine except I cannot log in as root.When I installed mySql I set a root password and also I created 2 accounts both admin.I can connect with the db from the command line with both but not as root.If I insert the root password the prompt disappears.I experimented a little and I can connect like this localhost/connecting.php with this code and any of the 2 accounts:

<?php
mysql_connect("localhost","Carlo","mypassword" or die(mysql_error());
echo "Connected to my SQL<br/>";
?>

of course I replace mypassword with 1 of the 2 accounts password,I don't know the purpose of the <br/>tag.
All the exercises in the tutorial assume that I connect like this:
$dbcnx = mysql_connect('localhost','root','mypassword'); which does not work in my case because of the root problem I think.So I am stuck is there a way to fix this?
Thanks for your help.

Member Avatar for diafol

<br/> is just 'decorative' - to enusre that the message appears on its own line and doesn't blled into the next lot of content.

I sounds as though you don't have an account for root/mypassword. Open up phpMyAdmin and have a look at privileges:

9b32f405dfe40dc8421d5fd47ff2cb99

You can then change the password.

<br/> is an HTML tag that is used to break line that is just user here to display suceeding statements from next line.
As for the problem is there for root password,there might be that either you are entering wrong root password or its created. http://dev.mysql.com/doc/refman/5.0/en/adding-users.html
There is 1 more possibilty that over your wamp server,you might have installed mysql with different root password.So if previous service is running then it won't allow password of next.
refer http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes

DO NOT USE THE MYSQL extension.

Although a lot of tuts will still use this, it has been superceeded by MySQLi.

You could also opt for, and one i use, PDO.

MySQLi basic connection:

$mysqli = new mysqli("localhost", "your_user", "your_password", "your_database");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
else {
..do something wonderful..
}

PDO & MySQL connection:

try 
{
    $dbh = new PDO('mysql:host=localhost;dbname=DATABASE_NAME', 'your_user', 'your_password');
} 
catch (PDOException $e) 
{
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
Member Avatar for diafol

Even though you may be using mysql, PDO and mysqli will use the same DB, so your user details (username/pw) will be the same. I concur with Squidge, moving to either alternative is worth doing now, before mysql extensions are deprecated.

I followed your advice and set the root password with phpMyAdmin,Now everything works fine, I can connect as root or as any other user with phpMyAdmin. From the command line propmpt however I can only log in as root.Is that how is supposed to be? Doing the tutorials I realize that these are probably a few years old and the code sometimes is not compatible with my latest version of php.That makes it difficult for a beginner like me so if you don't mind I'll probably have some more questions soon.I am doing good though, I figure out how to access the db from a web page and display the content and also customize the look of the table output.Thanks a lot.

There is one more option though not recommended as password is not encrypted.

Change in myhuge.ini file

#The following options will be passed to all MySQL clients
[client]
#password   = your_password

**Uncomment password and set password to some password,that will be passed to all mysql client
**

Note:- If your problem is solved then please mark the thread as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.