Go Back   CodingForums.com > :: Server side development > Ruby & Ruby On Rails

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-02-2007, 11:28 AM   PM User | #1
bhakti_thakkar
Regular Coder

 
Join Date: Sep 2006
Location: India Mumbai
Posts: 248
Thanks: 13
Thanked 1 Time in 1 Post
bhakti_thakkar is an unknown quantity at this point
how to connect to mysql

hi all ,
till now i was using mysql with apache and php. all is perfectly fine.but now i have started with ruby [just a day old in ruby on rails] and i am stuck up connecting to mysql rather even starting mysql using webrick.i jst dont know how to proceed....mysql 5.0 is installed on another LINUX machine and i even changed the localhost to the IP address of LINUX machine in database.yml file but still when on the command prompt i type the following i get mysql not recognized:
////////////////////////////////////

depot>mysql -u root -p

///////////////////////////////
Settings in database.yml file
development:
adapter: mysql
database: depot_development
username: root
password:
host: LINUX IP ADDRESS

Any help most appreciated. badly stuck. i had even posted the same in mysql section of this forum but i think i shuld have posted here as i think i am failing with some ruby/ rails settings.Please help
Thanks in advance
bhakti_thakkar is offline   Reply With Quote
Old 02-23-2007, 02:21 PM   PM User | #2
softsea
New to the CF scene

 
Join Date: Feb 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
softsea is an unknown quantity at this point
example

require "mysql"
my = Mysql::new("host", "user", "passwd", "db")
res = my.query("select * from tbl")
res.each do |row|
col1 = row[0]
col2 = row[1]
end
softsea is offline   Reply With Quote
Old 07-08-2007, 03:35 PM   PM User | #3
Janet Kellman
New to the CF scene

 
Join Date: Jul 2007
Location: USA
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Janet Kellman is an unknown quantity at this point
Quote:
Originally Posted by bhakti_thakkar View Post
hi all ,
till now i was using mysql with apache and php. all is perfectly fine.but now i have started with ruby [just a day old in ruby on rails] and i am stuck up connecting to mysql rather even starting mysql using webrick.i jst dont know how to proceed....mysql 5.0 is installed on another LINUX machine and i even changed the localhost to the IP address of LINUX machine in database.yml file but still when on the command prompt i type the following i get mysql not recognized:
////////////////////////////////////

depot>mysql -u root -p

///////////////////////////////
Settings in database.yml file
development:
adapter: mysql
database: depot_development
username: root
password:
host: LINUX IP ADDRESS

Any help most appreciated. badly stuck. i had even posted the same in mysql section of this forum but i think i shuld have posted here as i think i am failing with some ruby/ rails settings.Please help
Thanks in advance
mysql not recognized because it's installed on another server.
example of using mysql at ruby wrote softsea, anyway use right host in my = Mysql::new
Janet Kellman is offline   Reply With Quote
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
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:14 PM.


Advertisement
Log in to turn off these ads.