cancel
Showing results for 
Search instead for 
Did you mean: 

SQL Host Name

N/A

SQL Host Name

first time i'm using a SQL database, if i'm using a php script that, which needs to know the MYSQL Host/Database Server Address then what do i put in?

i'm on rumpus. thanks
3 REPLIES
N/A

SQL Host Name

Try "rumpus.force9.net" if used from a computer at home, or simply "rumpus" if used on a Force9 host.

(Just registered and already using MySQL -- you don't waste time!)
N/A

SQL Host Name

This has been discussed in this forum previously, is available on the F9 Support pages in PHP - a beginner's guide and you'll have received example PHP code in your F9 MySQL 'Database Creation details' confirmation e-mail!!!

But to recap for you, all you should need to do, is specify the MySQL hostname, database name and the username / password combination (supplied to you by F9) in the database connection strings (see the example below).

It is best to have this connection data (which includes your database password in clear text) as variables or classes that are included from a file that can't be accessed directly - there have been some threads about this in the CGI forum - this Passwords and stuff thread shows how to include a file with passwords.

It may also be worth looking at the PlusNet forums (probably the CGI Forum) on this (signin as guest with guest as your password if you are prompted for one).

As you said you were on rumpus, I assume you have got F9 to activate your database, if not, use the MySQL tool from the My Website portal tool.

You will need to specify a database connection string that comprises of the following:

Hostname: rumpus.force9.net
Username: <MySQL username> e.g. mutantcol
Password: <Your password>
Database: <Your database name> e.g. mutantcol_f9

You might need to specify a port number, if so, use the MySQL default of 3306.

The php code snippet below (from the PHP website), shows the connection strings (you need to authenticate (connect) to the database server, then tell it (select) which database you want).

Quote
<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
?>


So in your PHP code, you would use something like:
Quote
<?php
/* Connecting, selecting database */
$link = mysql_connect("rumpus.force9.net", "mutantcol", "<password>")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("mutantcol_f9") or die("Could not select database");
?>


This PHP and MySQL code shows how to make a simple query and return a result:

Quote
<?php
/* Connecting, selecting database */
$link = mysql_connect("mysql_host", "mysql_user", "mysql_password")
or die("Could not connect : " . mysql_error());
print "Connected successfully";
mysql_select_db("my_database") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT * FROM my_table";
$result = mysql_query($query) or die("Query failed : " . mysql_error());

/* Printing results in HTML */
print "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
print "\t<tr>\n";
foreach ($line as $col_value) {
print "\t\t<td>$col_value</td>\n";
}
print "\t</tr>\n";
}
print "</table>\n";

/* Free resultset */
mysql_free_result($result);

/* Closing connection */
mysql_close($link);
?>


Incidentally, you can use the F9 hosted phpMyAdmin to manage your database throught the F9 portal. I was just about to recommend SQLyog as a tool to use from your PC, but I see it's no longer freeware (but does have a 30 day trial period).

Finally, don't foget that all files containing PHP must be stored on the CGI server - cgi.<yourusername>.force9.co.uk otherwise, the PHP commands will be interpreted as standard HTML, producing errors when displayed on screen.

Regards

Neil
N/A

SQL Host Name

thanks, got it working fine now.

I've been a force9 member for a while, over a year. first time i've used the forums thats all.