PHP won’t connect to database
-
I have a problem with getting PHP to connect to mysql database
<?php
// connect and select a database
$link = mysql_connect(“vergil.u.washington.edu :18423”, “root”, “new_password”)
or die (“Couldn’t connect: Check to make sure that:<br>” .
“- your MySQL server is running
- you used the correct hostname (<tt>vergil/ovid</tt>)
- ” .
“ - you didn’t forget the ‘u’ in the hostname
- you added a colon with your port number after the hostname
- you used the username ‘root’
- you used the correct root password
- you didn’t forget to close a set of quotation marks
” .
“” .
“” .
“” .
“” .
“<br><br>”);
print “Connected successfully.<br>”;
$db = “mysql”;
mysql_select_db($db) or die(“Could not select the database ‘” . $db . “‘. Are you sure it exists?”);
// perform an SQL query
$query = “SELECT * FROM user”;
$result = mysql_query($query) or die(“Query failed”);
// print the result of the first row (row counting starts at zero)
printf(“Host: %s<br>\n”, mysql_result($result, 0, “Host”));
printf(“User: %s<br>\n”, mysql_result($result, 0, “User”));
printf(“Grant privilege: %s<br>\n”, mysql_result($result, 0, “Grant_priv”));
// free result set
mysql_free_result($result);
// close the connection
mysql_close($link);
?>
It won’t let me connect to the Database. do I have to install phpadmin?
I think the server already supports php since I looked at phpinfo() and there was
a MSQL heading. But I’m not sure, I’m new to PHP and mysql.
The topic ‘PHP won’t connect to database’ is closed to new replies.