Web Site Creator Web Hosting Help
   Using Ms Sql/MySQL with PHP


Here are three sample ways to connect to a database.  We recommend placing one of the below methods into an include file - a file that contains nothing but the info below and any other database access information so you only have to configure it once, regardless of how many times you use it, or how many pages use it.

Replace the username, password, and database with the information that relates to your specific database before using.

How to access SQL Server from PHP with out a DSN
If you have a SQL Server account with us, it is very easy to access your database from PHP. Here is sample code for establishing a connection to the database:

$server = "database1.ehost-services.com,1433";
$dbusername = "USERNAME"; //database username
$dbpassword = "PASSWORD"; //database password
$dbdatabase = "DATABASE"; //database name
$sqlconnect = @mssql_connect($server, $dbusername, $dbpassword) or die("Couldn't connect to SQL Server on $server");
$sqldb = @mssql_select_db($dbdatabase,$sqlconnect) or die("Couldn't open database $dbdatabase");

How to access SQL Server from PHP WITH a DSN
Every one of our web sites can utilize an MS Access database. You must create the database and upload it to your /Db directory. This is very important- it will not function correctly from any other directory. The /Db directory has special write access that lets you update your database. Here is sample code for establishing a connection to the database:

$dsn="UserDBConn"; //Replace this with the name of the DSN
$dbusername="USERNAME"; //database username
$dbpassword="PASSWORD"; //database password
$dbdatabase="DATABASE"; //database name

$sqlconnect = @odbc_connect($dsn, $dbusername, $dbpassword) or die("Couldn't connect to SQL Server using DSN $dsn");
$sqldb = @mssql_select_db($dbdatabase,$sqlconnect) or die("Couldn't open database $dbdatabase");

How to access MySQL Server from PHP
$server="mysqldb1.ehost-services.com";//database location
$dbusername="USERNAME"; //database username
$dbpassword="PASSWORD"; //database password
$dbdatabase="DATABASE"; //database name

$dbc = @mysql_connect ($server, $dbusername, $dbpassword) or die('Counld not connect to Mysql Server:' . mysql_error());
mysql_select_db ($dbdatabase) or die('Could not connect to the database:' . mysql_error());


Sign Up Now! Overview

Questions? Call sales at
1 (425) 274-4500
Or try our
Visit our Help Center where you can get simple and quick product support.
   is an affiliate of   , a leading domain name services company.
Copyright © 1998-2018 Enom LLC. All rights reserved. Terms & Conditions | Privacy Policy | Abuse Policy