Create a Database in Helm
The first thing you need to do is create a MySql database, username and password in Helm, if you haven't already done so.
If you haven't, then log into your Helm 4 account, go to your domain and click on the "MySql" icon. Then add a new database. Then add a new username and password for that database. Once you've done that, you can move on to connecting to it from your web site.
Connect your web site to your database
The easiest way is to create a file that contains your database connection information like this:
config.php
<?php
$hostname="localhost"; <-- leave this as localhost
$mysql_login="mylogin"; <-- enter your database username
$mysql_password="mypassword"; <-- enter your database password
$database="mydatabase"; <-- enter your database name
$table="mytable"; <-- (optional) you can include a table name here if you want
?>
The config.php file could be in an /includes folder.
Then you can create a connection script that will take the database configuration from config.php and establish a connection to the database.
connect.php
<?
error_reporting(0);
include 'config.php';
// connect to the database server
if (!($db = mysql_pconnect($hostname, $mysql_login , $mysql_password))){
die("Can't connect to database server.");
}else{
// select a database
if (!(mysql_select_db("$database",$db))){
die("Can't connect to database.");
}
}
// don't forget to close the mysql connection
?>
This file should also be saved in the /includes folder. This way all pages that need database access can reference this file in their scripts.
If you create a page called "somepage.php", that needs to contact the database, it can easily be done like this.
somepage.php
<?
include 'connect.php';
// Your code here to query the database.
?>
There's no need to also include the config.php file, because it's being called by connect.php.
I hope this helps.