Help Can't Connect to MySQL!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazycompsci
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 1:12 am

Help Can't Connect to MySQL!!!

Post by crazycompsci »

I'm relatively new to the whole PHP and MySQL thing here but definitely not a new developer. Here's what I've got:

Code: Select all

 
<html>
<body>
 
<?php
 
ini_set('display_errors', 1); 
error_reporting(E_ALL);
 
$conection = mysql_connect("localhost","root","",true);
 
if (!$connection)
{
  die('<div>Could not connect: ' . mysql_error() . '</div>');
}
else
{
  echo("Connected");
}
 
mysql_close($connection);
?>
 
</body>
</html>
 
It's producing this output:

Code: Select all

 
Notice: Undefined variable: connection in /Library/WebServer/Documents/index.php on line 11
Could not connect:
 
Now I know things are set up correctly since I can connect to MySQL using the workbench and command line. And the really odd thing is I have a WordPress blog set up as well and that has absolutely no issues connecting at all. I tried to see how it was doing the connection and was unsuccessful at replicating it. Any help would be MUCH appreciated.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Help Can't Connect to MySQL!!!

Post by flying_circus »

looks like you're missing an "n" in line 10?
crazycompsci
Forum Newbie
Posts: 2
Joined: Thu Jan 14, 2010 1:12 am

Re: Help Can't Connect to MySQL!!!

Post by crazycompsci »

yeah I just found it... thats what you get for coding at 2:30 in the morning with no sleep... :)
Post Reply