PDA

View Full Version : Database Connections MySql & PHP



forTheDogs
12-03-2007, 05:34 PM
Does anyone have a simple PHP data connection script for mysql that works on hostmaster?

I am getting an error message that no database was selected. The script works perfectly on my testing [wamp] server.

Does the file location/directory of the connection script matter? This is for an addon domain, not my main domain.

Any help would be greatly appreciated.

shadmego
12-03-2007, 06:39 PM
1. Did you remember to create the database in CPanel? This includes creating the user/password and attaching said user to the database.

2. Did you remember that the username AND the database will begin with your HM account name? accountname_dbname and accountname_usrname?

And lastly,

3. Did you remember that the host is localhost?


It should not matter if you are creating the DB for an addon domain or not. The databases are "attached" to your main HM account ... thus the reason for adding the account name to the beginning of database and usernames.

~regards

forTheDogs
12-03-2007, 07:05 PM
Jim Elliot: answers to your questions:

1. yes
2. yes
3. yes

Do I have to add an addon domain as an "access host' in the remote mysql? If so, how does one determine what that number is?

Thanks!

shadmego
12-03-2007, 07:12 PM
When you added this particular domain to your HM account, it created a directory in your public_html folder.

So your addon domain is now being served out of the /home/account/public_html/addon.com folder.

Because your addon domain is being served from the same account, but a different folder than, your main domain, "access" should be the same for both domains.

Incidentally, have you tried running this script (the access part of the script) from inside your main domain ... say, inside te public_html directory to make sure it works?

The only other thing I can think of is posting your *scrubbed* code so we can look at it to make sure there are no errors ...

~regards

forTheDogs
12-03-2007, 07:21 PM
Hi Jim: I ran it from hostmonster and got this message:
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/forthel4/public_html/spiritwood/Connections/conn_spirit.php:9) in /home/forthel4/public_html/spiritwood/login.php on line 53
[LOG OUT]

I don't understand what this means!!

forTheDogs
12-03-2007, 07:26 PM
Here's the script for my connection file:

<?php

$database_conn_spirit = "xxxxxxxx_xxxxxxxxxxxxxxxxxxx";
$username_conn_spirit = "xxxxxxxx_xxxxxxx";
$password_conn_spirit = "xxxxxxxxxxx";
$conn_spirit = mysql_connect('localhost', $username_conn_spirit, $password_conn_spirit) or trigger_error(mysql_error(),E_USER_ERROR);
?>

and this is the script from my log in page to select the db:




$db_select=mysql_select_db('database name', $conn_spirit);
if(!db_select) {
die('Database selection failed. .:' . mysql_error());
}

Thanks!

shadmego
12-03-2007, 07:30 PM
Without seeing your code, I cannot say for sure, but to my untrained eye, it looks like your code issues might not be related to your php code connecting to your database, but you might be sending multiple html headers to the same page, which your server is kindly telling you is a bad thing.

Have you looked up the error and/or line 53 of login.php yet?

Seb
12-03-2007, 08:14 PM
Check for any whitespace at the very top of your page. This will prevent you from altering the header (session_start()) further down your script.

shadmego
12-03-2007, 08:26 PM
$db_select=mysql_select_db('database name', $conn_spirit);
if(!db_select) {
die('Database selection failed. .:' . mysql_error());
}

Thanks!

Try this instead:



$db_select=mysql_select_db($database_conn_spirit);
if(!db_select) {
die('Database selection failed. .:' . mysql_error());
};


The reason for this is because you already made the connection in the previous script ... there really is no need to recreate thatconnection once it's established ... all you have to do is select the database, which is what this script is trying to do.

~regards

P.S. I'm not quite as strong with php as other here ... so I would get a second opinion on this.