SearchSearch   

Problems getting PHP and MySQL to play nice

 
   Webmaster Forums (Home) -> PHP MySQL RSS
Next:  EXAMPLE OF DIGITAL ATLAS IN PHP/MySQL  
Author Message
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 1) Posted: Fri Sep 26, 2008 11:50 am
Post subject: Problems getting PHP and MySQL to play nice
Archived from groups: comp>lang>php, others (more info?)

Hi all. Can't seem to get PHP to play nice with MySQL.

First I logged into MySQL, created the db, switched to it and then
granted (what I thought were) correct privileges:

----[%begin%]----

Macintosh-7:~ jason$ /usr/local/mysql/bin/mysql -u root

mysql> create database wes;
Query OK, 1 row affected (0.00 sec)

mysql> use wes
Database changed

mysql> grant all privileges on wes.* to user@localhost identified by
'changeme'
-> ;
Query OK, 0 rows affected (0.08 sec)

----[%end%]----

I then created a bit of PHP to test this...

----[%begin%]----

<?php

$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'changeme';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');

?>

----[%end%]----

But when I access that PHP page, I get:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to
local MySQL server through socket '/var/mysql/mysql.sock' (2) in /
Library/WebServer/Documents/wes/mysql_test.php on line 7
Error connecting to mysql

Any thoughts on what I'm doing wrong? I have checked to make sure
Apache and PHP are running. I can access scripts through localhost
just fine, the problem is only with MySQL.

Thanks much in advance,
Jason
Back to top
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 2) Posted: Fri Sep 26, 2008 12:12 pm
Post subject: Re: Problems getting PHP and MySQL to play nice
Archived from groups: per prev. post (more info?)

On Sep 26, 2:57 pm, "J.O. Aho" <u... RemoveThis @example.net> wrote:

> This is a quite common error when the mysql daemon isn't running, check that
> it's still running and the socket file is created in /var/mysql direcotry..
>
> --
>
>    //Aho

Hm.

Well, I check OS X's System Preferences and for the MySQL prefs it
says:

"The MySQL Database Server is started and ready for client
connections. ... The MySQL Server Instance is running."

I also tried two other variables for $dbhost ("localhost:3306" and ":/
usr/local/mysql/bin/mysql.sock"). Neither worked.

Any idea why it would be acting like it's not running when it is? =/

Again, thanks,
Jason
Back to top
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 3) Posted: Fri Sep 26, 2008 12:17 pm
Post subject: Re: Problems getting PHP and MySQL to play nice
Archived from groups: per prev. post (more info?)

On Sep 26, 2:57 pm, "J.O. Aho" <u....RemoveThis@example.net> wrote:

> This is a quite common error when the mysql daemon isn't running, check that
> it's still running and the socket file is created in /var/mysql direcotry..
>
> --
>
>    //Aho

Oh, forgot to mention that there isn't a /var/mysql directory. I'm
running OS X if that helps.

Jason
Back to top
bodhiSoma

External


Since: Sep 26, 2008
Posts: 6



(Msg. 4) Posted: Fri Sep 26, 2008 12:30 pm
Post subject: Re: Problems getting PHP and MySQL to play nice
Archived from groups: per prev. post (more info?)

On Sep 26, 2:57 pm, "J.O. Aho" <u....TakeThisOut@example.net> wrote:

> This is a quite common error when the mysql daemon isn't running, check that
> it's still running and the socket file is created in /var/mysql direcotry..
>
> --
>
>    //Aho

Figured it out through a rather bovine method.

Stopped the process then tried to connect by accident and got:

Macintosh-7:/usr/local/mysql/bin jason$ /usr/local/mysql/bin/mysql -
u root
ERROR 2002 (HY000): Can't connect to local MySQL server through
socket '/tmp/mysql.sock' (2)

Well, there's my socket. Changed the PHP to reflect this with:

$dbhost = ':/tmp/mysql.sock';

....and voila, connected.

Thanks!!!,
Jason
Back to top
J.O. Aho

External


Since: May 31, 2006
Posts: 2034



(Msg. 5) Posted: Fri Sep 26, 2008 8:57 pm
Post subject: Re: Problems getting PHP and MySQL to play nice
Archived from groups: per prev. post (more info?)

bodhiSoma wrote:

> But when I access that PHP page, I get:
>
> Warning: mysql_connect() [function.mysql-connect]: Can't connect to
> local MySQL server through socket '/var/mysql/mysql.sock' (2) in /
> Library/WebServer/Documents/wes/mysql_test.php on line 7
> Error connecting to mysql

This is a quite common error when the mysql daemon isn't running, check that
it's still running and the socket file is created in /var/mysql direcotry.


--

//Aho
Back to top
Kenoli

External


Since: Jan 22, 2008
Posts: 8



(Msg. 6) Posted: Mon Sep 29, 2008 9:23 am
Post subject: Re: Problems getting PHP and MySQL to play nice
Archived from groups: per prev. post (more info?)

On Sep 26, 12:30 pm, bodhiSoma <bodhis....DeleteThis@gmail.com> wrote:
> On Sep 26, 2:57 pm, "J.O. Aho" <u....DeleteThis@example.net> wrote:
>
> > This is a quite common error when the mysql daemon isn't running, check that
> > it's still running and the socket file is created in /var/mysql direcotry.
>
> > --
>
> >    //Aho
>
> Figured it out through a rather bovine method.
>
> Stopped the process then tried to connect by accident and got:
>
>    Macintosh-7:/usr/local/mysql/bin jason$ /usr/local/mysql/bin/mysql -
> u root
>    ERROR 2002 (HY000): Can't connect to local MySQL server through
> socket '/tmp/mysql.sock' (2)
>
> Well, there's my socket.  Changed the PHP to reflect this with:
>
>    $dbhost = ':/tmp/mysql.sock';
>
> ...and voila, connected.
>
> Thanks!!!,
> Jason

Glad you solved this. I got stuck on the same issue and figured it
out after a bunch of stress and have noticed posts on other lists
where people have had the same problem. Another way to deal with this
is to create the directory php is looking for and put a symbolic link
there to the socket file.

--Kenoli
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> PHP MySQL
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum