PDA

View Full Version : Cannot Connect MySQL Database


susan346031
07-07-2009, 09:16 AM
Hi,

I am unable to connect to the database and test Powerstore. I have been able to make a successful localhost connection in Dreamweaver and using the store.sql information (imported to my database & table) but no luck.


Notice: Undefined variable: database_test in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Notice: Undefined variable: localhost in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Notice: Undefined variable: localhost in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 67

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 67

In the menu.php, lines 65 & 67, here is the code:
65 mysql_select_db($database_locahost, $localhost);

67 $menuwriter_productcategories = mysql_query($query_menuwriter_productcategories, $localhost) or die(mysql_error());


Since it references $localhost, I also checked localhost.php--
$hostname_localhost = "localhost";
$database_localhost = "test";
$username_localhost = "durable";
$password_localhost = "****";
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);


Any help would be appreciated! :)
Thanks

SH

Ray Borduin
07-07-2009, 09:21 AM
According to the error you have $database_test on line 65 and not $database_localhost so maybe you didnt' upload the page but it seems like the code you are showing does not correspond to the code generating the error.

susan346031
07-07-2009, 09:32 AM
Hi Ray,
You are correct, I tried to specify the specific table, but even with database_localhost, the error is the same. I refreshed, here is the current error.


Notice: Undefined variable: database_locahost in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Notice: Undefined variable: localhost in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 65

Notice: Undefined variable: localhost in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 67

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\htdocs\DurableToys\CSSMenuWriter\cssmw_home\men u.php on line 67

Thank you

Ray Borduin
07-07-2009, 09:41 AM
That means that the page you are viewing doesn't have a require_once() for the connection. That is why the variable is not defined. Add the connection include on top of the page where the menu is located and it should correct the problem.

susan346031
07-07-2009, 09:44 AM
There is an includes command in the menu.php page. Do I need to modify it?


<?php require_once('../../Connections/localhost.php'); ?><?php } // End MenuWriter ignore connection includes ?>

Thanks

susan346031
07-07-2009, 09:58 AM
When I went to the Live Data view in Dreamweaver on menu.php, I also got an error regarding the WA_Globals
(An error occurred while requesting the document from the testing server:)


Notice: Undefined variable: WAGLOBAL_localRoot in C:\htdocs\DurableToys\CSSMenuwriter\cssmw_home\men u_3fgoomf88b.php on line 2
Notice: Undefined variable: WAGLOBAL_remotelRoot in C:\htdocs\DurableToys\CSSMenuwriter\cssmw_home\men u_3fgoomf88b.php on line 3
Warning: strpos() [function.strpos]: Empty delimiter in C:\htdocs\DurableToys\CSSMenuwriter\cssmw_home\men u_3fgoomf88b.php on line 6
Warning: strpos() [function.strpos]: Empty delimiter in C:\htdocs\DurableToys\CSSMenuwriter\cssmw_home\men u_3fgoomf88b.php on line 10

Here are the lines (2 & 3 of the menu.php in reference to WA_Globals
$WA_localRoot = "".$WAGLOBAL_localRoot."";
$WA_remoteRoot = "".$WAGLOBAL_remoteRoot."";

and 6 & 10
if ((strpos($WA_curURL,strtolower($WA_localRoot)) !== false && strpos($WA_curURL,strtolower($WA_localRoot)) == 0) && (strlen($WA_localRoot) >= strlen($WA_remoteRoot) || strpos($WA_curURL,strtolower($WA_localRoot)) === 0)) {
$assumedRoot = $WA_localRoot;

if (strpos(strtolower($WA_thisFile), strtolower($assumedRoot)) === 0) {
$WA_thisFile = substr($WA_thisFile, strlen($assumedRoot));


Here is the info in WA_Globals:
$WAGLOBAL_localRoot = "/DurableToys/";
$WAGLOBAL_remoteRoot = "/DurableToys/";

Local Root is C:\htdocs\DurableToys\
Remote Root is http://localhost/DurableToys/

??

Ray Borduin
07-07-2009, 10:04 AM
Not the menu.php page the page where the menu is located.

This error means your globals include is not on that page either.

susan346031
07-07-2009, 10:09 AM
Here are the includes (including WA_Globals) for the index.php page
I believe this is what you're referring to....

<?php require_once( "WA_Globals/WA_Globals.php" ); ?>
<?php require_once('Connections/localhost.php'); ?>

Ray Borduin
07-07-2009, 10:10 AM
Is that the page you are browsing when you see these errors? Are those on top of the page? That doesn't make sense... are you sure you are viewing that page. If so it should not say those variables are not defined because they are defined in that include.

susan346031
07-07-2009, 10:12 AM
Yes, I am refreshing the index.php page, with those includes that return those errors.

Ray Borduin
07-07-2009, 10:14 AM
Do you have a url where I can view it? Maybe the locations of those files has changed? If they are included, and the variables are defined in them, then you should not get an error that those variables are not defined.

susan346031
07-07-2009, 10:18 AM
I agree, which is why I am frustrated. :)

Right now, I am only working locally--cannot connect to MySQL database via Dreamweaver on my host... :\ And am not comfortable yet with all of the configuration changes to go live for that. However, if you wouldn't mind some steps I am able to try.

Thanks

susan346031
07-07-2009, 10:25 AM
http://hornharmony.fatcow.com/toy/ is where I put it....and as expected, I am getting a cannot connect to MySQL error.

Ray Borduin
07-07-2009, 10:44 AM
Yes... but notice you aren't getting the undefined variable errors.

Now you are getting an error connecting to the database:

localhost.php on line 9

This means that the specified database name is incorrect.

On the live server you probably can't use "localhost" you need to use the database ip address provided by the service provider.

susan346031
07-07-2009, 10:50 AM
I was told that I couldn't connect to my hosting MySQL (fatcow.com) server via Dreamweaver.

Ray Borduin
07-07-2009, 10:58 AM
This is not via dreamweaver. This is via your web page. You aren't getting an error in Dreamweaver you are getting an error when viewing on your web site.

You need to connect to the hosting mySQL server when actually viewing the web page.

susan346031
07-07-2009, 11:01 AM
They had me generate code that I replaced the Connections/localhost.php includes in index.php page with:
<?php
$link = mysql_connect('hornharmony.fatcowmysql.com', 'durable', '*password*');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db(toy_test);
?>

However, I am still getting an error related to the localhost, which I am going to configure now that I have information on how to connect...

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /hermes/web05b/b854/moo.hornharmony/toy/CSSMenuWriter/cssmw_home/menu.php on line 65

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /hermes/web05b/b854/moo.hornharmony/toy/CSSMenuWriter/cssmw_home/menu.php on line 67

Ray Borduin
07-07-2009, 11:05 AM
You can't just remove and replace the code in the connections folder like that.

You should use:


$hostname_localhost = "hornharmony.fatcowmysql.com";
$database_localhost = "your live database name";
$username_localhost = "durable";
$password_localhost = "****";
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);

susan346031
07-07-2009, 11:15 AM
I also noticed this message (in the heading)
Connected successfully
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /hermes/web05b/b854/moo.hornharmony/toy/index.php:2) in /hermes/web05b/b854/moo.hornharmony/toy/WA_eCart/WA_eCart_Definition_PHP.php on line 479

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /hermes/web05b/b854/moo.hornharmony/toy/index.php:2) in /hermes/web05b/b854/moo.hornharmony/toy/WA_eCart/WA_eCart_Definition_PHP.php on line 479

I updated the localhost.php page with the information, and then changed the Connections includes back, referencing the locahost.php


I get only one message (!)

No database selected.

susan346031
07-07-2009, 11:27 AM
I didn't change any code in localhost.php; I only modified the includes in the index.php file, and when it successfully connected, I used the configurations to update localhost.php.

However, as I mentioned before, the only error now is the No Database Selected.

I Then went back to localhost.php and clicked on the Live Data view, and got these errors:
Warning: mysql_pconnect() [function.mysql-pconnect]: Unknown MySQL server host 'hornharmony.fatcowmysql.com (11004) in C:\htdocs\DurableToys\Connections\localhost_6oitvm fce0.php on line 9

Fatal Error: Unknown MySQL server host 'hornharmony.fatcowmysql.com (11004) in C:\htdocs\DurableToys\Connections\localhost_6oitvm fce0.php on line 9

Ray Borduin
07-07-2009, 11:51 AM
Right...because you cannot connect to your database in Dreamweaver you are going to have to update that file when going live or viewing locally.

Locally use "localhost" and live use "hornharmony.fatcowmysql.com"

You should be updating the value in the connections folder.

Once you have it working live. Then update the connection on your local computer and don't upload it again in the future so that your local connection can be different than your live connection information. The same information won't work both live and in DW... you host has told you that.

susan346031
07-07-2009, 12:09 PM
The connections folder is up to date, as far as I can see. It is uploaded live, which should produce the dummy index.php page, but I am only seeing the "No Database Selected" when I refresh.

Obviously, I am missing something--do I need to change WA_Globals to reflect the remote root?

Thanks

Ray Borduin
07-07-2009, 12:18 PM
No. You are only having trouble with your connection file, so that is the only file you need to update to make it work.

susan346031
07-07-2009, 12:21 PM
This is my localhost.php page.

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_localhost = "hornharmony.fatcowmysql.com";
$database_localhost = "toy_test";
$username_localhost = "durable";
$password_localhost = "****";
$localhost = mysql_pconnect($hostname_localhost, $username_localhost, $password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);
?>

The database is the live database, (toy_test) located with Fatcow.com

susan346031
07-07-2009, 12:51 PM
Ray,

I went back to my testing server, and it works without any problems. Thanks for your help.