Quick Search:
Oracle PL/SQL Code Library
Find Or Post Oracle Jobs
Oracle Discussion & Chat
 Perl Code: SQL Insert Example Jump to:  
Category: >> Perl Code >> SQL Insert Example Bookmark and Share

<< lastnext >>

Snippet Name: SQL Insert Example

Description: Here we add two records to the database using an INSERT statement. The data to be entered can be gathered from an HTML form.

Comment: (none)

Language: PERL
Highlight Mode: PERL
Last Modified: March 05th, 2009

# Use the DBI module 
USE DBI QW(:sql_types); 
# Declare local variables 
MY ($databaseName, $databaseUser, $databasePw, $dbh); 
MY ($stmt, sth, @newRow); 
MY ($telephone); 
# Set the parameter values for the connection 
$databaseName = "DBI:mysql:yourWebSite_com"; 
$databaseUser = "yourLoginId"; 
$databasePw = "yourLoginPassword"; 
# Connect to the database 
# Note this connection can be used to 
# execute more than one statement 
# on any number of tables in the database 
$dbh = DBI->connect($databaseName, $databaseUser, 
$databasePw) || DIE "Connect failed: $DBI::errstr\n"; 
# Create the statement. 
$stmt = "INSERT INTO Phonebook (Id, Name, Telephone) 
VALUES (‘BBBBB', ‘Joe Smith', ‘212-555-1212')"; 
# Prepare and execute the SQL query 
$sth = $$dbh->prepare($$stmt) 
|| DIE "prepare: $$stmt: $DBI::errstr"; 
$sth->execute || DIE "execute: $$stmt: $DBI::errstr"; 
# INSERT does not return records 
# Clean up the record set 
# We could add another record here as well 
# Create the statement.
$stmt = "INSERT INTO Phonebook (Id, Name, Telephone) VALUES (‘CCCCC', ‘Marcy Jones', ‘402-555-1212')"; 
# Prepare and execute the SQL query $sth = 
|| DIE "prepare: $$stmt: $DBI::errstr"; 
$sth->execute || DIE "execute: $$stmt: $DBI::errstr"; 
# Clean up the record set and the database connection 

Oracle Magazine
and Oracle White Papers

SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 37 users online    © 2009 psoug.org

Forgot your password?