View Single Post
Old 11-06-2007, 09:47 AM   PM User | #4
boboch
New to the CF scene

 
Join Date: Oct 2007
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
boboch has a little shameless behaviour in the past
To connect from a PHP script, just put this in your file::
<?
mysql_connect("db.YOURDOMAIN", "DBUSERNAME", "DBPASSWORD");
mysql_select_db("DBNAME");
?>
using the same substitutions for the bold terms as above, plus substituting DBPASSWORD with your own mysql password.

Example:


mysql_connect("db.joesmith.com", "joe", "secret");

mysql_select_db("joeydb");



To connect from a perl script, put this in your file::

#!/usr/bin/perl
use DBI;

$database = "DBNAME";
$hostname = "db.YOURDOMAIN";
$port = "3306";
$username = "DBUSERNAME";
$password = 'DBPASSWORD';

$dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";

$dbh = DBI->connect($dsn, $username, $password) or die("Could not connect!");

$sql = "SELECT * FROM mytable";

$sth = $dbh->prepare($sql);
$sth->execute;


while(($column1, $column2) = $sth->fetchrow_array)
{
print "C1 = $column1, C2 = $column2n";
}


$dbh->disconnect;

where DBNAME, DBUSERNAME, and DBPASSWORD are your database name, database username and database password, and where YOURDOMAIN is your website's domain name with no "www." in front, for example, "mysite.com", or if you are not hosting your own domain name with us, then "mysite.modwest.com".
boboch is offline   Reply With Quote