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?
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:
If the 'use test' command returned an error, you know your test database has not been created, so go ahead and create it by:
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.
Change your
or die("Could not connect");
todie(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
SQLYogWebYog Community Edition (they used to have a much better website for it, but clearly they want you to fork out for the paid version)