/    Sign up×
Community /Pin to ProfileBookmark

mysql_connect troubles

Hello, everybody.
I just downloaded MySQL, completing my Apache-PHP-MySQL trio. I created a VERY basic php page to do a test connection to the MySQL server… it failed. I’ve been trying to figure out why the error’s occuring, but I need some help.
[I am running everything on a Mac OS 10.4 (Leopard)]

Here’s the code (I’ve excluded the outer html). I’ve replaced my password with “PASSWORD”

[code=php]
<?php
$con = mysql_connect(“localhost”,”phpUser”,”PASSWORD”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
else
{
echo “<p>Good Job</p>”;
}
?>
[/code]

I have a user set up in MySQL named “phpUser” with host “localhost” with password “PASSWORD”

Can anyone shed light on why this won’t work?
Thanks a bunch,
StPretz

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@mrwilsonApr 30.2008 — Might help if you told your connection which Database to use

[CODE]
<?php
$con = mysql_connect("localhost","phpUser","PASSWORD");
mysql_select_db ("$DB Name", $con);

if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "<p>Good Job</p>";
}

[/CODE]
Copy linkTweet thisAlerts:
@afigueroaApr 30.2008 — providing the error would help as well
Copy linkTweet thisAlerts:
@saintpretz59authorApr 30.2008 — SHOOOT. :p Forgot the error. I knew i was forgetting something:

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

Could not connect: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

mrwilson: I think that the problem occurs before any database needs ot be selected. Obviously, this script doesn't DO anything. I just wanted to see if I could connect.

To afigueroa and everyone else who currently thinks I'm an idiot.... yeah, I'm an idiot. :p
×

Success!

Help @saintpretz59 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...