Problems using Perl DBI to edit database entries - basic stuff
Hello. I am taking a Perl class in college and we've briefly covered SQL and moved on. We have a term project and we can do whatever we want. My project will rely strongly on an SQL Database so I am trying to learn as much about Perl DBI as I can to get things up and going.
I am basically making CGI scripts that take user input from forms and then put that into database tables so I will need to be able to search, edit, insert and delete data entries. I am essentially having trouble getting on my feet with how to manipulate data in my database.
My instructor set up a database for me which I can access and edit but I am already having trouble with my script. I am hoping that someone can help me figure out what things I need to include in my code to get this working.
So far, I have a CGI script that takes a few fields of form data from a webpage: username, email, and password. I am attempting to put this into an SQL table called "user_accounts" and this table has three colomns named "username", "password", and "email".
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)"
I have googled this error message and I have edited my code a little here and there and gotten a few different errors which I do not fully understand or know how to fix. I have read over the pages of my textbook that cover DBI and I have looked at Oreilly's Perl DBI book and I have googled countless times and I just cant figure out how to simply make some lines of code that access and edit my SQL database. I really need some help so I can get things functioning for my project as I am going to eventually run out of time.
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
cgi::session::driver::dbi
CGI::Session::Driver::DBI(3pm) User Contributed Perl Documentation CGI::Session::Driver::DBI(3pm)NAME
CGI::Session::Driver::DBI - Base class for native DBI-related CGI::Session drivers
SYNOPSIS
require CGI::Session::Driver::DBI;
@ISA = qw( CGI::Session::Driver::DBI );
DESCRIPTION
In most cases you can create a new DBI-driven CGI::Session driver by simply creating an empty driver file that inherits from
CGI::Session::Driver::DBI. That's exactly what sqlite does. The only reason why this class doesn't suit for a valid driver is its name
isn't in lowercase. I'm serious!
NOTES
CGI::Session::Driver::DBI defines init() method, which makes DBI handle available for drivers in Handle - object attribute regardless of
what "\%dsn_args" were used in creating session object. Should your driver require non-standard initialization you have to re-define init()
method in your .pm file, but make sure to set 'Handle' - object attribute to database handle (returned by DBI->connect(...)) if you wish to
inherit any of the methods from CGI::Session::Driver::DBI.
STORAGE
Before you can use any DBI-based session drivers you need to make sure compatible database table is created for CGI::Session to work with.
Following command will produce minimal requirements in most SQL databases:
CREATE TABLE sessions (
id CHAR(32) NOT NULL PRIMARY KEY,
a_session TEXT NOT NULL
);
Your session table can define additional columns, but the above two are required. Name of the session table is expected to be sessions by
default. You may use a different name if you wish. To do this you have to pass TableName as part of your " \%dsn_args ":
$s = CGI::Session->new('driver:sqlite', undef, {TableName=>'my_sessions'});
$s = CGI::Session->new('driver:mysql', undef,
{
TableName=>'my_sessions',
DataSource=>'dbi:mysql:shopping_cart'.
});
To use different column names, change the 'create table' statement, and then simply do this:
$s = CGI::Session->new('driver:pg', undef,
{
TableName=>'session',
IdColName=>'my_id',
DataColName=>'my_data',
DataSource=>'dbi:pg:dbname=project',
});
or
$s = CGI::Session->new('driver:pg', undef,
{
TableName=>'session',
IdColName=>'my_id',
DataColName=>'my_data',
Handle=>$dbh,
});
DRIVER ARGUMENTS
Following driver arguments are supported:
DataSource
First argument to be passed to DBI->connect(). If the driver makes the database connection itself, it will also explicitly disconnect
from the database when the driver object is DESTROYed.
User
User privileged to connect to the database defined in "DataSource".
Password
Password of the User privileged to connect to the database defined in "DataSource"
Handle
An existing DBI database handle object. The handle can be created on demand by providing a code reference as a argument, such as
"<sub{DBI-"connect}>>. This way, the database connection is only created if it actually needed. This can be useful when combined with
a framework plugin like CGI::Application::Plugin::Session, which creates a CGI::Session object on demand as well.
"Handle" will override all the above arguments, if any present.
TableName
Name of the table session data will be stored in.
LICENSING
For support and licensing information see CGI::Session
perl v5.12.4 2011-07-08 CGI::Session::Driver::DBI(3pm)