Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 how to connect to mysql

View previous topic View next topic Go down 
AuthorMessage
Database
Member
Member
Database

Posts : 318
Join date : 2012-03-04

how to connect to mysql Empty
PostSubject: how to connect to mysql   how to connect to mysql EmptyFri Jul 27, 2012 11:08 pm

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
Back to top Go down
Database
Member
Member
Database

Posts : 318
Join date : 2012-03-04

how to connect to mysql Empty
PostSubject: Re: how to connect to mysql   how to connect to mysql EmptyFri Jul 27, 2012 11:08 pm

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
Back to top Go down
Database
Member
Member
Database

Posts : 318
Join date : 2012-03-04

how to connect to mysql Empty
PostSubject: Re: how to connect to mysql   how to connect to mysql EmptyFri Jul 27, 2012 11:09 pm

Database wrote:
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
Back to top Go down
Database
Member
Member
Database

Posts : 318
Join date : 2012-03-04

how to connect to mysql Empty
PostSubject: Re: how to connect to mysql   how to connect to mysql EmptyFri Jul 27, 2012 11:09 pm

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".
Back to top Go down
Sponsored content




how to connect to mysql Empty
PostSubject: Re: how to connect to mysql   how to connect to mysql Empty

Back to top Go down
 

how to connect to mysql

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» MySQL over SSL socket?
» Problem when using ORDER BY a date field from MySQL
» How do i select entries from a mySQL database to use as options in a form?

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: how to connect to mysql Edit-trash Useless :: Trash-