Dave,
What you have is mostly a mis-ordering of the lines. try this instead:
Once $dbh is defined, a "prepare" call is needed to get the SQL statement into the object.
As a side note, for best coding practice, you should have a " -w" after the perl line at the top (like this: "#!/usr/local/bin/perl -w") OR "use warnings;" to be sure you're told about things that could be mistakes. It's also a very good idea to "use strict;", which forces you to declare variables with "my" before you can use them. This also helps to make in obvious what variable scope you're expecting and can really reduce the amount of hair you pull out during a project.
HTH!
Steve
Quote:
Originally Posted by Dave247
Here is my Perl code with the DBI code in there to access the database:
When I run this, I get this error message: "Can't locate object method "disconnect" via package "INSERT INTO user_accounts (username, email, password)"Dave247
HI to everyone, I have been for a very long time in my life a GUI user, and now that i have to use a Solaris 5 terminal, i am not sure how to do some things:
Downloading stuff from the internet:
How do i do that?
in a GUI you just click on the link and start downloading automatic, but i have... (4 Replies)
We ran into an issue trying to install DBI and DB2 modules for perl for AIX from the link
http://www-306.ibm.com/software/data/db2/perl/
We tried to install the DBI module using
bash# perl -MCPAN -e 'install DBI'
command. However we ended up with the following error.
Stop.
... (3 Replies)
Hey,
I connected with Cygwin and this command:
"ssh -Y USER@web.com"
Then trying to open a program, but this error appeared:
"Cannot open X display: DISPLAY variable unset"
what do I have to do?
Thanks.
Alex (3 Replies)
hi i am trying to connect to an oracle database using dbi and i get this ::
Driver has not implemented the disconnect_all method. at /opt/perl/lib/site_perl/5.8.0/sun4-solaris/DBI.pm line 575
END failed--call queue aborted.
for all i know, the script was working earlier, but has... (1 Reply)
Hi, i have some queries on installing the Perl DBI and the DBD Oracle.
I know that i have to install the DBI first. I have the source files in a folder in my home directory.The commands to install arecd /home/DBI
Perl Makefile.PL
make
make installI would like to know, after executing these... (4 Replies)
Hello !
I am working on a small Perl script that should connect to the MySQL server, will select all the databases one by one and do some queryes on each. I started working on it but I just saw that on the DBI manual page there's no method for changing the working database. Am I missing... (2 Replies)
Hi,
I want to connect perl with the mysql to select and so on but the connection don't work
code
#!/usr/bin/perl
BEGIN {
# PERL MODULES WE WILL BE USING
use DBI;
$dbh = DBI->connect('DBI:mysql:C:\Program Files\MySQL\MySQL Server 5.0\data\db1','','pass') or die $DBI::errstr;}
#... (1 Reply)
Hi there, I have a bit of code similar to below (which ive actually got from perldoc, but mine is similar enough)
$sth = $dbh->prepare(q{ SELECT region, sales FROM sales_by_region });
$sth->execute;
my ($region, $sales);
# Bind Perl variables to columns:
$rv =... (4 Replies)
Hi All,
I installed DBI module in a non INC location and using it in my script via "use lib".
But it throw the below error at the "use DBI" step.
Please help
Usage: DBI::_install_method(dbi_class, meth_name, file, attribs=Nullsv) at /xx/xxx/xxxxx/xxxxx/oracle/lib/DBI.pm/oracle/lib/DBI.pm line... (2 Replies)
Discussion started by: prasperl
2 Replies
LEARN ABOUT DEBIAN
netsds::dbi
NetSDS::DBI(3pm) User Contributed Perl Documentation NetSDS::DBI(3pm)NAME
NetSDS::DBI - DBI wrapper for NetSDS
SYNOPSIS
use NetSDS::DBI;
$dbh = NetSDS::DBI->new(
dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432',
login => 'user',
passwd => 'topsecret',
);
print $db->call("select md5(?)", 'zuka')->fetchrow_hashref->{md5};
DESCRIPTION
"NetSDS::DBI" module provides wrapper around DBI module.
CLASS API
new(%params) - class constructor
$dbh = NetSDS::DBI->new(
dsn => 'dbi:Pg:dbname=test;host=127.0.0.1;port=5432',
login => 'user',
passwd => 'topsecret',
);
dbh() - DBI connection handler accessor
Returns: DBI object
This method provides accessor to DBI object and for low level access to database specific methods.
Example (access to specific method):
my $quoted = $db->dbh->quote_identifier(undef, 'auth', 'services');
# $quoted contains "auth"."services" now
call($sql, @bind_params) - prepare and execute SQL query
Method "call()" implements the following functionality:
* check connection to DBMS and restore it
* prepare chached SQL statement
* execute statement with bind parameters
Parameters:
* SQL query with placeholders
* bind parameters
Return:
* statement handler from DBI
Example:
$sth = $dbh->call("select * from users");
while (my $row = $sth->fetchrow_hashref()) {
print $row->{username};
}
fetch_call($sql, @params) - call and fetch result
Paramters: SQL query, parameters
Returns: arrayref of records as hashrefs
Example:
# SQL DDL script:
# create table users (
# id serial,
# login varchar(32),
# passwd varchar(32)
# );
# Now we fetch all data to perl structure
my $table_data = $db->fetch_call("select * from users");
# Process this data
foreach my $user (@{$table_data}) {
print "User ID: " . $user->{id};
print "Login: " . $user->{login};
}
begin() - start transaction
commit() - commit transaction
rollback() - rollback transaction
quote() - quote SQL string
Example:
# Encode $str to use in queries
my $str = "some crazy' string; with (dangerous characters";
$str = $db->quote($str);
INTERNAL METHODS
_add_sets() - add initial SQL query
Example:
$obj->_add_sets("set search_path to myscheme");
$obj->_add_sets("set client_encoding to 'UTF-8'");
_add_attrs() - add DBI handler attributes
$self->_add_attrs(AutoCommit => 1);
_check_connection() - ping and reconnect
Internal method checking connection and implement reconnect
_connect() - connect to DBMS
Internal method starting connection to DBMS
EXAMPLES
samples/testdb.pl
SEE ALSO
DBI, DBD::Pg
TODO
1. Make module less PostgreSQL specific.
AUTHOR
Michael Bochkaryov <misha@rattler.kiev.ua>
LICENSE
Copyright (C) 2008-2009 Net Style Ltd.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
perl v5.10.1 2010-04-28 NetSDS::DBI(3pm)