473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

connect to mysql database

Hi everyone,
i am a totally rookie in perl. I have a project which needs to use perl to connect to mysql database. I already installed the perl mysql driver, MySQL, and use perl code which i found on the internet to connect to the mysql database. However, it says the connection was denied. I didnt set username and password for the database.

So which problems might result in this situation, need help please
Jun 26 '07 #1
5 1818
miller
1,089 Expert 1GB
What code have you tried so far to connect to a database?

- Miller
Jun 26 '07 #2
What code have you tried so far to connect to a database?

- Miller
hi miller,
here is the code

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl -w
  2. #connect_test.pl
  3.  
  4. use strict;
  5. use DBI;
  6.  
  7. print "Available Database Drivers:\n";
  8. print "*" x 40, "\n";
  9. print join("\n", DBI->available_drivers()), "\n\n";
  10.  
  11.  
  12. my %attr => ( RaiseError => 0 );
  13.  
  14. my $dbh = DBI->connect("DBI:mysql:dbname=Orkut_data:localhost", "root", "root")
  15.     or die("Error: $DBI::errstr");
Jun 26 '07 #3
miller
1,089 Expert 1GB
Obviously the first place that you should start is the documentation.
cpan DBI#connect

Secondly, whenever I create a database connection, I always extrapolate the settings into variables. This is a way of self-documenting, so that you can be assured of what goes where.

Expand|Select|Wrap|Line Numbers
  1. my $dbname = 'Orkut_data';
  2. my $dbhost = 'localhost';
  3. my $dbuser = 'root';
  4. my $dbpass = 'root';
  5.  
  6. my $dbh = DBI->connect("DBI:mysql:dbname=$dbname:$dbhost", $dbuser, $dbpass)
  7.     or die "Error: $DBI::errstr";
  8.  
You claimed that you set no user or pass, but as you can see you are trying to connect to the database with the u/p root/root. Is this what you want?

Also, whenever a connection fails, the DBI::errstr should have given you a useful error message. If you continue to have problems, then tell us what those are if you can't translate their meaning.

- Miller
Jun 26 '07 #4
i am using EMS SQL Manager to create a database.

It does not work. it says the access was denied.
i also installed MySQL Server 5.0/

so why i cant create a database?
Jun 27 '07 #5
savanm
85
Hi

use strict;
use DBI;
#connect to the database
my $dbh = DBI->connect("DBI:mysql:database=perldbi;host=localhos t",
"root","");
#$dbh->do("CREATE TABLE foo (id INTEGER, name VARCHAR(20))");
#$dbh->do("DROP TABLE foo");
my $sth = $dbh->prepare("SELECT * FROM foo");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
}
$sth->finish();
$dbh->disconnect();
Jun 27 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: Mr Dygi | last post by:
Hi, PHP 4.3.4 installed manually from package *.zip and Apache 2. I have a problem with this simple code: <?php $link = mysql_connect("127.0.0.1","","") or die("Could not connect: " ....
1
by: Jordy | last post by:
Environment: Sun servers running solaris 2.8 Php 4.3.6 Apache 1.3.29 Mysql 4.1.1 phpMyAdmin 2.6.0-alpha1 phpAds 2.0 PhpMyadmin and phpAds don't succeed to connect the MySql database when
7
by: atlasyeo | last post by:
Hi, my first time posting on a newsgroup. anyway, let's cut to the chase. I'm trying to migrate mysql database form one server to another server. So I copied the data from /var/lib/mysql to the...
0
by: Bill Hernandez | last post by:
Hi, I've been writing software on the mac since 1987, but am brand new at unix/php/mysql, and that's where I'm headed so I'm reading everything I can get my hands on, but like anything else...
1
by: ikrabbe | last post by:
Hi, I want to set up a mysql server in an embedded process. I managed to start the server in my program as described through mysql_server_init() Now I need a client connection to this...
5
by: news.telia.net | last post by:
Hi! I have a question. I have installed php and mysql on an apache-server on windows and I can't connect to the server. I tried to create a database (since I am trying to learn howto). My...
2
by: Martin | last post by:
Hi all. I have a fully functional page hosted on my PC that uses PHP and connects to MySQL on my PC to generate it's code. I now have some web hosting available which includes both PHP and...
2
by: 111mike | last post by:
Hello, Here's my problem. I cannot connect to mysql database using odbc string connections or dns. I keep getting a "cannot connect to mysql server localhost." I'm running windows XP Pro and...
4
by: d3vkit | last post by:
Okay so I am at a loss here. I have a website that I've previously had no trouble connecting to the mysql DB on. I have an include to a connect file with the relevant connection info, and it was...
6
by: markodilore | last post by:
Hey Guys, you helped me once when I tryied to create a database : "Access denied for user ''@'localhost' ". On my Mac OS 10.4, I had no problem creating database and modifying it from the terminal....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.