PDA

View Full Version : New to PHP-database connection problems



kitty
06-09-2004, 07:30 PM
Domain name:gurukitty.com
Okay, not only am i new to PHP i've never used PHPMyAdmin before.
Im trying to install a directory script made by a friend of mine and i get this error: "Cannot connect to the MySQL server. Please check your variables and re-upload the config.php file or try again later."

No matter what i do.
I created a database called simpledir in my PHPadmin ... i think =\
Maybe someone could give me a little rundown on how to create a new empty database and a user for it? Just to make sure i did everything right?

There is only one file i should be editing according to her instructions and thats config.php, this is the code on it:


<?php

// SimpleDir 2.2
// Copyright 2003 Tara, http://www.ice-star.net. All rights reserved.
// Released August 28, 2003

# your host (usually "localhost"; check with your hosting provider if this doesn't work)
$dbhost = "localhost";

# the name of the database where the information for this script will be stored
$dbname = "simpledir";

# username for the database
$dbuser = "kitty";

# username's password
$dbpass = "pass";

/* name of the table for the configuration options to be stored in */
$tbconfig = "config";

/* name of the table for the links */
$tblinks = "links";

/* name of the table for the categories */
$tbcats = "cats";

# header file, to be included on add.php and listing.php
# if this file is not in the same directory as add.php and listing.php, please put the absolute path to the file below
# please make sure that you have the extension correct
# ex: /home/gurukitty.com/dir/header.inc.php
$headerv = "header.inc.php";

# footer file, to be included on add.php and listing.php
# if this file is not in the same directory as add.php and listing.php, please put the absolute path to the file below
# please make sure that you have the extension correct
# ex: /home/gurukitty.com/dir/header.inc.php
$footerv = "footer.inc.php";

// DO NOT EDIT BELOW THIS LINE!!
$db = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("<p>Cannot connect to the MySQL server. Please check your variables and re-upload the config.php file or try again later.</p>");
@mysql_select_db ($dbname) or die ("<p>Cannot select the database. Please check that the specified user has access to the database, that the database and username exist, and that the password is

correct.</p>");

?>

wildjokerdesign
06-09-2004, 08:33 PM
Try "root" as your $dbuser and your main password as the $dbpassword and see if that gets you past the error.

When you go into phpMyAdmin use the drop down on the left to see if the database you created is there. If not go go back to the first screen and there is the option to create a database. All you should have to do is input the name of the database and submit it.

Not knowing what the rest of the php is on the script not sure what else you would have to do from that point. Hopefully there is an install.php or something similiar that well set up the tables for you mentioned in the config file looks like there should be three from the config file... config, links and cats.

Let use know how it goes.

kitty
06-09-2004, 08:56 PM
Thank you for replying.
Unfortunatly that didnt work either.
you can look at the whole package right here http://gurukitty.com/dir/simpledir2_2.zip
Or just the readme that was included with it here, with the installation instructions: http://gurukitty.com/dir/readme.html

I have hostees that will want their own databases as well, is there a way to create a database for a hostee, without giving them my domain password?

wildjokerdesign
06-10-2004, 06:21 AM
Ok did you check in phpMyAdmin to see if the database was there? You should see a drop down list when you first log in and it should be in the drop down list. You can also access your databases with the link in the right frame that says databases. If it is there next I am going to lead you through setting up a user. This is what you can use for the other database you want to set up that you mentioned also. You can use the same user for both if you want.

On the Home page of phpMyAdmin click on Privileges in the left frame. You should see a table that shows your users. Below that you should find a link that says "Add New User" On this next page you see the from to enter the info for the new user. Go adhead and enter the user name leaveing the dropdown set to "Use text field". Next for Host use the dropdown menu to select localhost and it well fill in the box for you on the right. Lastly enter the password you want for this user and leave the dropdown set toe "Use text field". Now below that you want to set the Privledges for this user. According to the readme for this script they need the following privledges: ADD, ALTER, INSERT, DELETE, UPDATE, SELECT.
I think that ADD is actually CREATE in this section. (I am doing a bit of guessing here just from looking at what is available and the little bit I know agout this.) Submit the info with th GO button.

Now go back to your config.php and alter it to include the user and password you just created. Then upload it and go to your create.php page and see if it works. I am asumming from reading the readme that this page well lead you through the rest of the set up of the script. Don't forget to remove that file once you have finnished setting the script up.

Let me know if you have questions.

dansroka
06-10-2004, 06:32 AM
I think wildjoker has you covered. Looking at the code, it gives you that error message when the variables $dbhost, $dbuser, $dbpass don't match what you have on your system. From the snippet you gave us, your $dbpass (password) is still set to the sample one included in the original code. You'll have to change this to your master password, like wildjoker is explaining.

Looking at the code, another thing to check before you get this running is to ask your friend if you need to set up the tables her code uses, or if it will do it for you. On a quick glance, her code is looking for three tables:


/* name of the table for the configuration options to be stored in */
$tbconfig = "config";

/* name of the table for the links */
$tblinks = "links";

/* name of the table for the categories */
$tbcats = "cats";

In MySQL, a database can contain any number of 'tables'. The tables are where the actual data lives. For example, if you have a database 'my_store', it could contain tables for 'inventory', 'expenses', etc. The 'inventory' table might then contain fields for product name, quantity, price, etc.

If her code is assuming that those three tables exist, and that they contain specific fields, your code won't work.

kitty
06-10-2004, 10:29 AM
Thank you both for replying.

I hate to say this, wildjokerdesign...but, yeah, i did do all that. :?
Exactly how you said it, in fact.
I still get that error.



dansroka, yeah i already asked her that, and the create.php creates the table for me, so all i need to do is cretae a blank database. The password and username i created for the database were kitty and pass. Those are ones i entered.

FZ
06-10-2004, 11:55 AM
Is PhpMyAdmin working for you? If it is, then you know that your mySQL server is not the problem: it is the script itself. Also, keep in mind that the password for the username "root" is not necessarily the same as your account password: when you install mySQL via your Site Manager, it asks you to choose a master password.

FZ
06-10-2004, 12:02 PM
Here's another thing you can try... Change this line:


$db = mysql_connect ($dbhost, $dbuser, $dbpass)

to:


$db = mysql_connect ('localhost', 'root', 'pass')

The reason I suggest that is because I remember a while ago some code of mine refused to connect to the database when the details were passed to mysql_connect as variables: they had to be declared as constants, or "hard coded", or I had to explicitly set the variables to be global.

Let us know how it works out.

wildjokerdesign
06-10-2004, 01:47 PM
Fayez, thanks for mentioning that the password for mysql may not be the main one but what was entered when mysql was set up. I didn't even think of that. I think kitty's mysql is setup right sinc she did use phpMyAdmin to create the database and even created a second user and password. I have a feeling your code change may do the job.

Kitty, I was not able to open up the zip file you listed at the first since it seems to be corrupted (or at least my local computer thinks so) otherwise I would try and intall the program on my test account to see if I could find a solution. I'll try to save it again to my local computer and see if I can get it to unzip.

kitty
06-15-2004, 05:02 PM
Okay, i will try those things and let you know asap so you can help anyone else with similar problems.
thank you and sorry for my late reply.

kitty
06-20-2004, 01:48 PM
Hmmm, it's still not working.
I get errors when i try to create a new user for the databases

MySQL said:
Access denied for user: 'root@localhost' (Using password: YES)

Stuff like that, when i create a new user in PHPMyAdmin.

Thank you for all your help.

FZ
06-20-2004, 01:59 PM
It definitely should not be saying that - something is messed up, big time... I think your best bet would be to contact WestHost and tell them about that error message. Are you getting that in PhpMyAdmin? If yes, then does it let you list your databases/tables, etc. but not let you do stuff like add users? Or does it just show that message whenever you try to get into PhpMyAdmin?