CGI Programming with Perl by Scott Guelich
Author:Scott Guelich [Scott Guelich, Shishir Gundavaram, and Gunther Birznieks]
Language: eng
Format: epub
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9781449326791
Publisher: O'Reilly Media
Published: 2011-12-31T16:00:00+00:00
Database manipulation
Database manipulation in DBI is quite simple. All you need to do is pass the create table, insert, update, or delete statement to the do method on the database handle. Immediately, the command will be executed:
$dbh->do( "insert into Player_Info values ('Hakeem Olajuwon', 10, 27, 11, 4, 2)") or die "Cannot do: " . $dbh->errstr( );
Database querying
Querying a database with DBI involves a few more commands since there are many ways in which you might want to retrieve data. The first step is to pass the SQL query to a prepare command. This will create a statement handle that is used to fetch the results:
my $sql = "select * from Player_Info"; my $sth = $dbh->prepare($sql) or die "Cannot prepare: " . $dbh->errstr( ); $sth->execute( ) or die "Cannot execute: " . $sth->errstr( ); my @row; while (@row = $sth->fetchrow_array( )) { print join(",", @row) . "\n"; } $sth->finish( );
Once the prepare command has been issued, the execute command is used to start the query. Since a query expects return results, we use a while loop to get each database record. The fetchrow_array command is used to fetch each row that is returned as an array of fields.
Finally, we clean up the statement handle by issuing the finish method. Note that in most cases we do not have to explicitly call the finish method. It is implicitly called by virtue of the fact that we have retrieved all the results. However, if the logic of your program decided to stop retrieving records before the entire statement had finished being retrieved, then calling finish is necessary in order to flush out the statement handle.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
API Testing and Development with Postman by Dave Westerveld(3594)
Learning C# by Developing Games with Unity 2020 by Harrison Ferrone(2594)
Software Architecture for Busy Developers by Stéphane Eyskens(2298)
2021 Beginners Guide to Python Programming Language: A Crash Course to Mastering Python in One Hour by Elmer Gary & Elmer Gary(1884)
Machine Learning for Algorithmic Trading by Stefan Jansen(1628)
Hands-On ROS for Robotics Programming by Bernardo Ronquillo Japón(1572)
Delphi GUI Programming with FireMonkey by Andrea Magni(1456)
Game Development Projects with Unreal Engine by Hammad Fozi & Goncalo Marques & David Pereira & Devin Sherry(1400)
Cloud Native with Kubernetes by Alexander Raul(1373)
Datadog Cloud Monitoring Quick Start Guide by Thomas Kurian Theakanath(1346)
Software Architecture Patterns for Serverless Systems by John Gilbert(1337)
Practical Node-RED Programming by Taiji Hagino(1335)
Automate It with Zapier by Kelly Goss(1318)
Practical System Programming for Rust Developers by Prabhu Eshwarla(1312)
Delphi Programming Projects by William Duarte(1292)
Mastering React Test-Driven Development by Daniel Irvine(1287)
Developing Multi-Platform Apps with Visual Studio Code by Ovais Mehboob Ahmed Khan & Khusro Habib & Chris Dias(1253)
Ghidra Software Reverse Engineering for Beginners by A. P. David(1243)
Learn Spring for Android Application Development by S. M. Mohi Us Sunnat(1235)
