473,760 Members | 8,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problems getting PHP and MySQL to play nice

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

mysqlcreate database wes;
Query OK, 1 row affected (0.00 sec)

mysqluse wes
Database changed

mysqlgrant 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
Sep 26 '08 #1
5 1574
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
Sep 26 '08 #2
On Sep 26, 2:57*pm, "J.O. Aho" <u...@example.n etwrote:
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:330 6" 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
Sep 26 '08 #3
On Sep 26, 2:57*pm, "J.O. Aho" <u...@example.n etwrote:
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
Sep 26 '08 #4
On Sep 26, 2:57*pm, "J.O. Aho" <u...@example.n etwrote:
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
Sep 26 '08 #5
On Sep 26, 12:30*pm, bodhiSoma <bodhis...@gmai l.comwrote:
On Sep 26, 2:57*pm, "J.O. Aho" <u...@example.n etwrote:
This is a quite common error when the mysql daemon isn't running, checkthat
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
Sep 29 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2298
by: Chris | last post by:
<apologies for cross-posting> Hi All, I am based in the UK and have been doing some private work for a client which involved setting up a database and scripts to search it and display results etc, all the usual stuff. The work was at about the halfway point when the client asked for a time estimate for the whole project. I sent him this and he wrote back
6
3865
by: das dsf | last post by:
Hi there! I have both PHP 4.0( RPM) installed and MySQL 4.0.20 installed with the mysqld daemon up and running. But when I look at the output of phpinfo() , I do not see it there, which is worrisome and so I tried to recompile PHP and do ./configure with the --with-mysql=path but I don't really know where my mysql's header files should be , is there any way to find that out by using any of the mysql commands? I did try to do...
0
417
by: Jeff Harbin | last post by:
I've spent the last 2 days trying to begin using mysql. I've purchased 3 books and read huge chunks of the documentation provided with the mysql zip file. I've downloaded 'mysql-4.0.18-win.zip', unzipped it, run the WinMySqlAdmin program, and everything seems fine. I'm trying to use it on WindowsXP on a new machine. I'm trying to learn mysql from scratch using the command line before I play with what I'm assuming are GUI for mysql. ...
14
2324
by: Jim Hubbard | last post by:
Are you up to speed on the difficulties in using the 1.1 .Net framework? Not if you are unaware of the 1,596 issues listed at KBAlertz (http://www.kbalertz.com/technology_3.aspx). If you are going to use .Net......I highly recommend signing up for the free KBAlertz newsletter at http://www.kbalertz.com/default.aspx. Looking at all of the errors and quirks sometimes makes me wonder if this thing is really ready for prime time.
6
1805
by: MBS | last post by:
Yeah, read the previous posts...I did that. None answer my question. I just installed PHP 5.0.4, Apache 2.0.54, and MySQL 4.1.13 a few days ago on WinXP SP2. My goal is to learn to use these programs. I cannot, absolutely cannot connect to MySQL using PHP. I've tried everything possible including the mysqli functions. I have no idea what is wrong. I don't get any error messages at all. It's almost as if PHP stops processing the...
3
4366
by: Mike | last post by:
I have transferred the data from Access to MySQL using MySQL's tool. The transfer worked great and saved me a lot of time (thanks MySQL). Now I'm trying to get the Access database, or a new access database, to talk across ODBC and see the data. I created the DSN through the control panel and it works without error. How do I setup Access so it can see the data. The data
1
2189
by: amandeep.bhatia1 | last post by:
Hello Friends, I am working on a project to support internationalization for a existing project. While supporting UTF-8 I am facing a problem , while doing POC. I have a C string which I have declared as const char* utf8buf = "Bienvenue à l'anglais ";
6
1890
by: JNeko | last post by:
Hello all, awesome site! I guess I am technically not a beginner in JAVA, but from my code you would not realize it! I don’t expect anyone to help me with this, but I figure I might as well as try and ask. Any help is really appreciated; this should be a piece of cake…driving me crazy. I am writing a simple program (from a book for fun) that creates a deck of cards, shuffles them, gives the user a card, and asks if the next card will be...
2
2449
by: chromis | last post by:
Hi there, I've been reading an OOP book recently and it gives some nice Adaptor / Template patttern code to wrap around the php Mysql functions. I thought that I'd try and create a Simple Address book using similar methods, but I'm having some trouble with using the class functions (I'm new to OOP in PHP 5). So far I've written a Contact Book class and a Contact class. The Contact Book class has add, edit, delete and display functions for...
0
10107
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9945
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9900
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9765
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8768
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7324
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5214
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3863
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.