01-15-2008
Perl Database access
Hi,
I tried to run this code but it isnt giving me any output or errors.
My aim is to retrieve the row based on the flag name(this is the primary key).
flag_test is my table
This is how i ran it:
perl read_db.pl flag1
flag1 is the criteria in where clause
--------
this is my code:
#!/usr/bin/perl
use DBI;
sub read_db
{
$dbh = DBI -> connect('DBI:Oracle:mercury','student','learn') || die "unable to connect:$DBI::errstr";
my $dbh = DBI->connect();
my $sql = qq/select flag_name, f_name, l_name from flag_test where flag_name =?/;
my $sth = $dbh->prepare($sql);
$sth->execute();
my ($col1, $col2, $col3);
$sth->bind_col(1, \$col1);
$sth->bind_col(2, \$col2);
$sth->bind_col(3, \$col3);
while ($sth->fetch) {
print "$col1, $col2, $col3\n";
}
}
could somebody help me with this?
thanks,
mercury
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
Hello,
I am a newborn baby to Unix and I was told that it was possible to have Microsoft Access databases on a Unix web server. I am using Perl to interface and query the Access database, which puts the information into the appropriate fields of a web page. Then updated information is submitted... (1 Reply)
Discussion started by: spiderling
1 Replies
2. Programming
Hey,
I want to access oracle database through Unix C programming.. Can you through me some light on that... (5 Replies)
Discussion started by: kavi
5 Replies
3. UNIX for Advanced & Expert Users
Hi!
I need to access two diferent databases allocated in a linux server through PHP. I know in the php.ini file I can't configure some parameters as odbc.default_db... but I can't configure it.
I've already installed unixodbc drivers
Can Anybody point me to a tutorial web o teach me how... (0 Replies)
Discussion started by: ncatdesigner
0 Replies
4. Shell Programming and Scripting
Hi
i have the following code:
if(($line!=1) and (@field!='\$')){
print ( "\nTRY TO CONNECT TO DATABASE................\n");
my $dbh = DBI->connect($dsn, $user, $pass);
print ("CONNECTED TO DATABASE\n");
eval
... (1 Reply)
Discussion started by: chriss_58
1 Replies
5. Shell Programming and Scripting
hi guys,
I am using the following code in order to access a database.
#!/usr/bin/perl
print "READ DATA FROM DATABASE\n";
use DBI;
use strict;
#use DBD::Oracle;
my $user='reassure';
my $pass='R3Assur3';
#my $dsn="dbi:Oracle:orcl";
my $dsn='dbi:Oracle:cobscs.world';
my $dbh =... (1 Reply)
Discussion started by: chriss_58
1 Replies
6. Shell Programming and Scripting
Hell all,
I have the following snippet of code:
$sql=qq{select * from (
select to_char(t.start_time_timestamp,'yyyy/mm/dd hh24:mi:ss') start_time,t.s_p_number_address, null cos_icsa_code, null cos_icsa_subcode from cc_unrated_msc_flow t
union
select... (2 Replies)
Discussion started by: chriss_58
2 Replies
7. IP Networking
Hi! :D
I'm new here, and I will appreciate all the help you can give.
This is the problem we are trying to solve at my office.
At office 1 we have SCO UNIX 5.0.can't remember last number. On it runs database software on which we input/read/modify data throughout terminal software, on remote... (1 Reply)
Discussion started by: PNemesis
1 Replies
8. Shell Programming and Scripting
i want to access database (sql script) within a unix script.
help me (2 Replies)
Discussion started by: chamaraa
2 Replies
9. UNIX for Dummies Questions & Answers
Hello all,
is it possible to write a script in order to connect to a database, load data in a specific domain and execute the corresponding command? (3 Replies)
Discussion started by: FelipeAd
3 Replies
10. AIX
Hi,
I am running a JDBC:ODBC code to access .mdb file in my windows system successfully but, not able to access MS Access mdb file in AIX Unix box. when I am trying to run the same piece of code in AIX Unix box it is saying "No Suitable Driver". I need some immediate help. (0 Replies)
Discussion started by: thirunp
0 Replies
LEARN ABOUT DEBIAN
data::printer::filter::db
Data::Printer::Filter::DB(3pm) User Contributed Perl Documentation Data::Printer::Filter::DB(3pm)
NAME
Data::Printer::Filter::DB - pretty printing database objects
SYNOPSIS
In your program:
use Data::Printer filters => {
-external => [ 'DB' ],
};
or, in your ".dataprinter" file:
{
filters => {
-external => [ 'DB' ],
};
DESCRIPTION
This is a filter plugin for Data::Printer. It filters through DBI's handlers (dbh) and statement (sth) objects displaying relevant
information for the user.
DBI is an extremely powerful and complete database interface. But it does a lot of magic under the hood, making their objects somewhat
harder to debug. This filter aims to fix that :)
For instance, say you want to debug something like this:
use DBI;
my $dbh = DBI->connect('dbi:DBM(RaiseError=1):', undef, undef );
A regular Data::Dumper output gives you absolutely nothing:
$VAR1 = bless( {}, 'DBI::db' );
Data::Printer makes it better, but only to debug the class itself, not helpful at all to see its contents and debug your own code:
DBI::db {
Parents DBI::common
Linear @ISA DBI::db, DBI::common
public methods(48) : begin_work, clone, column_info, commit, connected, data_sources, disconnect, do, foreign_key_info, get_info, last_insert_id, ping, prepare, prepare_cached, preparse, primary_key, primary_key_info, quote, quote_identifier, rollback, rows, selectall_arrayref, selectall_hashref, selectcol_arrayref, selectrow_array, selectrow_arrayref, selectrow_hashref, sqlite_backup_from_file, sqlite_backup_to_file, sqlite_busy_timeout, sqlite_collation_needed, sqlite_commit_hook, sqlite_create_aggregate, sqlite_create_collation, sqlite_create_function, sqlite_enable_load_extension, sqlite_last_insert_rowid, sqlite_progress_handler, sqlite_register_fts3_perl_tokenizer, sqlite_rollback_hook, sqlite_set_authorizer, sqlite_update_hook, statistics_info, table_info, tables, take_imp_data, type_info, type_info_all
private methods(0)
internals: {
}
}
Fear no more! If you use this filter, here's what you'll see:
SQLite Database Handle (connected) {
dbname: file.db
Auto Commit: 1
Statement Handles: 0
Last Statement: -
}
Much better, huh? :)
Statement handlers are even better. Imagine you continued your code with something like:
my $sth = $dbh->prepare('SELECT * FROM foo WHERE bar = ?');
$sth->execute(42);
With this filter, instead of an empty dump or full method information, you'll get exactly what you came for:
SELECT * FROM foo WHERE bar = ? (42)
Note that if your driver does not support holding of parameter values, you'll get a "bindings unavailable" message instead of the bound
values.
SEE ALSO
Data::Printer
perl v5.14.2 2011-05-30 Data::Printer::Filter::DB(3pm)