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!
<?php
$username = "root";
$password = "";
$hostname = "localhost";
//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
?>
But all I get is a blank page. I have run this code which works:
Whenever you get a blank screen back it is likely that you have a syntax error on your page and the PHP directive display_errors is disabled.
Try using this connection string..
$db = mysql_connect("$hostname", "$username", "$password");
if (!$db) { die('Could Not Connect'.mysql_error()); }
mysql_select_db("$dbname",$db);
This should give you the exact mysql error in the event that you are not able to make a connection.
You can also attempt to put this at the top of the page just below <?php
ini_set('display_errors', 1);
That will enable display_errors assuming you have permission to do so on your web server.
The other things you can attempt to change are localhost with 127.0.0.1 and obviously you'll want to make sure you supply a password for your $password variable.