Solved

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

Posted on 2007-12-06
13
6,020 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
ID: 20425502
to set root password:

mysqladmin -u root password newpassword
0
 
LVL 1

Author Comment

by:mrmyth
ID: 20425717
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
ID: 20426106
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
ID: 20426215
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
ID: 20427553
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
ID: 20427648
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 1

Author Comment

by:mrmyth
ID: 20427774
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
ID: 20428249
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
ID: 20433265
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
ID: 20433288
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
ID: 20433336
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
ID: 20451705
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
ID: 20451738
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

911 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

23 Experts available now in Live!

Get 1:1 Help Now