Solved

Dreamweaver - localhost mySQL database won't connect to my php site

Posted on 2007-12-06
13
6,013 Views
Last Modified: 2013-12-12
I have a php site that has been running off a mySQL database very well.

I want to make some changes to the site but I want to run a testing environment on my local computer.

I'm using a Macintosh running Leopard. I installed MySQL and activated php and have the site running locally except that I can't connect to the local database from my local site. I'm using Dreamweaver to make the connection file. I'm using local host with root and no password.

I used navicat to duplicate the database from what it online. I am able to connect to this database on my localhost and everything seems fine until I try to connect to it using my Dreamweaver. Then it can't locate the database. I checked the settings and they are the same as on Navicat, which sees the database fine.

Any suggestions?

Also I'd like to put a password on the root user. How do I do that?
0
Comment
Question by:mrmyth
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 3

Expert Comment

by:blckholehorizon
Comment Utility
to set root password:

mysqladmin -u root password newpassword
0
 
LVL 1

Author Comment

by:mrmyth
Comment Utility
thanks for the reply

i opened terminal and put in exactly what you typed and it said unknown "mysqladmin: command not found"
0
 
LVL 10

Expert Comment

by:ray-solomon
Comment Utility
Sounds like you are in a user account and you will need to switch to the root account instead.

type:

su

in the terminal and then the root password.
This should give you permission to use mysqladmin.

0
 
LVL 10

Expert Comment

by:ray-solomon
Comment Utility
hmm, I just read that the root user is disabled by default on Mac OS X and you cannot use the su command to switch to root.

Instead use:

sudo

http://www.macdevcenter.com/pub/a/mac/2002/10/22/macforunix.html
0
 
LVL 16

Assisted Solution

by:rbudj
rbudj earned 100 total points
Comment Utility
Did you start Apache (or other) service?  I use WAMP (search google) for my local testing and it works perfectly with Dreamweaver 8 and CS3.  However, you have navigate through the Start menu to find the link that says "Start Apache"
0
 
LVL 3

Expert Comment

by:blckholehorizon
Comment Utility
to make sure the services are running, run netstat -a | grep tcp

make sure mysql is running on port 3306 ( or whatever port you have it on), and apache on port 80

after installing apache, it will not start automatically at boot time, until you tell it to do so by adding it as a service.  mysql either (unless you used the gui installer to do so)

if they are running, then make sure there is no firewall prohibiting access to them.
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 1

Author Comment

by:mrmyth
Comment Utility
All the services seem to be running.

I put a password on the root, but it seems when I use Navicat to look at my mySQL database, and use the username root, it still has no password.

My local website still can't access the MySQL database for some strange reason, but Navicat has no problem accessing the database.

I try to connect to it in Dreamweaver and it says "unknown error"

I get this
"Warning: mysql_pconnect() [function.mysql-pconnect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Libarry/WebServer/Documents/MYWEBSITEFOLDER/Connections/conn_WEBSITE.php on line 9."

I don't think the firewall would have anything to do with it since it's local right?

0
 
LVL 3

Accepted Solution

by:
blckholehorizon earned 200 total points
Comment Utility
are you using an options file for connections?  that could explain why certain connections work, and some don't.  Try connecting over a TCP/IP socket instead of a socket file. also use 'localhost' instead of the IP address for a tcp/ip connection.

If still using a socket file, do the connecting programs have the rights to access the socket file if you are using?
0
 
LVL 1

Author Comment

by:mrmyth
Comment Utility
I got into a whole thing with the socket file and it seems to be getting closer.

Now it appears that the local website is trying to access the database, but it still can't.

I'm not getting the error that says it can't find the mysql.sock file

I followed these directions that I found:
"Bring the mysql.sock to PHP
One problem that has come about with MySQL and Leopard is the location of the mysql.sock file. Previously, the default location for this file was in the /tmp directory. That location has now moved to the /var/mysql directory. PHP will look for it there. Unfortunately, the default location from the MySQL will still place it in the old location. We can fix this by creating a my.cnf configuration file in the /etc directory. Save a file with the following contents to /etc/my.cnf:

[client]
socket = /var/mysql/mysql.sock

[mysqld]
socket = /var/mysql/mysql.sock

In the terminal window, type the following commands to create the directory for the sock file:

sudo mkdir /var/mysql
sudo chown _mysql /var/mysql"

Now I still can't connect to the database when I try to add it in Dreameaver.
I get "an unidentified error has occured"


0
 
LVL 1

Author Comment

by:mrmyth
Comment Utility
As far as Dreamweaver goes, I still can't get it to open that database, but when I put in all the pertinent data the connection does occur at the website level.

I was able to configure the php to work on the localhost by following the directions outlined here

http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/

especially the section that I recounted above

The Dreamweaver problem is still happening where it says "an unidentified error has occurred" when I try to connect to the database from within Dreamweaver.
0
 
LVL 10

Assisted Solution

by:ray-solomon
ray-solomon earned 200 total points
Comment Utility
Read the mysql manual for mac os x installation and also read all the user comments for tips.
http://dev.mysql.com/doc/refman/5.0/en/mac-os-x-installation.html

There is a dreamweaver comment in the user comments as well.




I would recommend creating a new php file then access it in your browser if you have apache and php working and configured properly on the computer.  This connection code is for testing purposes only to see what specific error messages are returned. It is helpful in correcting basic connection mistakes.

<?php

define('DB_HOST', 'localhost'); // stays as localhost
define('DB_USERNAME', 'your-database-username');
define('DB_PASSWORD', 'your-database-password');
define('DB_NAME', 'your-database-name');

@mysql_connect(DB_HOST,DB_USERNAME,DB_PASSWORD) or die(mysql_error());
@mysql_select_db(DB_NAME) or die(mysql_error());

?>
0
 
LVL 1

Author Comment

by:mrmyth
Comment Utility
Thanks for the advice. The final step of getting it to work was just to make sure that I set a testing site. I made it the same as the testing folder on my computer that I'm using and Dreamweaver can now connect.
If I would have just read the steps in the database connection box I wouldn't have had this final problem.


0
 
LVL 1

Author Comment

by:mrmyth
Comment Utility
In retrospect I think I should have just downloaded MAMP to properly setup the LAMP server on my mac. I assume it would resolve some of these problems.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now