What Do SQL Perl Scripts Do?

SQL Perl scripts use the Perl language to create a connection and query the database server. You use the connection to query data from the database in order to create interactive, dynamic content for your Web readers. You also use the scripts to insert data -- such as a user registration form -- into the database for later retrieval.

  1. Purpose

    • Because you cannot use Perl syntax for a database script, programmers and database administrators must use SQL code to edit or query the data. The script uses the Perl connection libraries to connect to the database and run the code. The libraries translate the Perl Web server language to the database driver language.

    Connection

    • You must connect to the database before you run the scripts. The following code connects to an Oracle database to prepare it for your Perl scripts:

      my $dbh = DBI->connect('DBI:Oracle:customers')

      The database to which the script connects is "customers." The Perl libraries handle any code needed to connect, so you just need to specify the server type and the database name.

    Implementation

    • After you create the connection, create the script that runs on the database server. The script you use depends on what you want to do with the data. For instance, if you want to retrieve a list of orders for a customer, the following SQL script applies:

      select * from orders where customerid=44

      This script retrieves a list of orders for a customer with the ID of 44.

    Warning

    • When using the SQL language in a Web page, make sure to scrub the data from any characters that can potentially be used for a so-called SQL injection hack. This type of hack exploits a website's security vulnerability by allowing hackers to insert SQL code into Web forms on the website, then use the code to steal data or delete data from the database.

Related Searches:

References

Comments

Related Ads

Featured