preface 
 
  Look_up Engine  
 
  email how to  
 
  counter  
 
  regex  
 
  search engine  
 
  home  
 
  ask us  
 

 

Perl scripting


Applications


OO Perl


Perl & Databases


Search a word:
   



© The scientific sentence. 2010

Perl API functions
Perl and databases

API functions

1. prepare() function

The SQL "SELECT" statement is done by using the API prepare() function. The result is stored in the key word $sth (Statement handle object).

2. execute() function

A statement is executed by using the API function execute().

3. finish() function

The Stattement handle is released by the API function finish().

4. fetchrow_array() function

The API function fetchrow_array() fetches all the results one by one and printing those results.

5. commit function

$dbh->commit or die $dbh->errstr; We finalize an operation by the commit function when everything goes fine. No changes are possible after this operation.

6. frollback function

If we want to revert back the changes made, we use rollback API operation: $dbh->rollback or die $dbh->errstr;

7. AutoCommit function

This option can be used to avoid write commit function each time we want a query to be accomplished. Instead of issuing a lot of commits, we then set one time "Autocommit" after a connection call. my $dbh = DBI->connect($dsn, $userid, $password, {AutoCommit => 1}) or die $DBI::errstr; AutoCommit can take value 0 or 1.

8. begin_work API function

begin_work API function turns AutoCommit off until the next call to commit or rollback that will turn AutoCommit on again. $rc = $dbh->begin_work or die $dbh->errstr;

9. "do" function

Sometimes, there is no outputs from an operation. For example If we are doing an UPDATE, INSERT, or DELETE. We can just use "do" statement to execute a command. For example the command: $dbh->do('DROP TABLE table name'); returns a true value if it succeeded, and a false value if it failed. In the case it succeeds it returns the number of affected rows.

10. RaiseErrors function

The API RaiseErrors option handles errors automatically when we make a connection. This option is convenient when we want to abort a program instead of returning a failure code if an arror occurs. my $dbh = DBI->connect($dsn, $userid, $password, {RaiseError => 1}) or die $DBI::errstr; RaiseError takes value 0 or 1.

11. Disconnecting Database

To disconnect Database connection, we use the disconnect API function "disonnect". $rc = $dbh->disconnect or warn $dbh->errstr; Once it is issued, some Database systems commit changes automatically, whereas others rollback any changes. When AutoCommit is not used, it is safe to call commit or rollback before calling disconnect.
  
Google
Web
ScientificSentence
 




chimie labs
|
scientific sentence
|
java
|
php
|
green cat
|
contact
|


© Scientificsentence 2007. All rights reserved.