Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I know there have been many similar questions, but as far as I can tell, most of the other people have gotten further than I have...

I'm trying to get a WAMP setup happening.

I've got PHP and Apache running and talking to each other. PHP is in c:\PHP Apache is in it's default program files folder. mySQL is in it's default install location. I have localhost setup at D:\public_html\

I'm able to navigate to localhost and see html and php files.

But I have a simple mySQL test file:

<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer='localhost';

// username and password to log onto db server
$dbUser='root';
$dbPass='';

// name of database
$dbName='test';

    $link = mysql_connect("$dbServer", "$dbUser", "$dbPass") or die("Could not connect");
    print "Connected successfully<br>";
    mysql_select_db("$dbName") or die("Could not select database");
    print "Database selected successfully<br>";

// close connection
mysql_close($link);
?>  

When I try and open this, I get "could not connect"

Now, I haven't even created a database yet, because I can't log into mySQL with phpmyadmin-so I think I've done something wrong in my mySQL install because they aren't talking to each other.

I guess my main question is how do I first create a database in mySQL to be sure I have even installed it correctly?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

It would help to open up a command prompt, and navigate to your mysql bin directory (if it isn't in your classpath). From here, login to mysql by:

mysql -uroot -p
use test;

If the 'use test' command returned an error, you know your test database has not been created, so go ahead and create it by:

CREATE TABLE test (
id INT,
data VARCHAR(50)
);

Your php looks fine, and should ideally be able to communicate with the mySQL DB instance named test, so long as such a DB instance is created. I would suggest using packaged WAMP setups like Wampserver or XAMPP, which let you focus on the actual development of your php site, instead of spending those hours on setting up your environment.

share|improve this answer
    
agreed-I went ahead and just downloaded xampp and was up and running in 10 minutes :-D –  Joel May 17 '10 at 6:37
    
Glad it helped, cheers. –  Shrinivas May 17 '10 at 6:41
add comment

Change your or die("Could not connect"); to die(mysql_error()); - this will give you a lot more information about what went wrong.

As far as creating databases etc go, you'll need to use a management tool. PHPMyAdmin is a popular one, personally I prefer SQLYog WebYog Community Edition (they used to have a much better website for it, but clearly they want you to fork out for the paid version)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.