Chapter 24 - MySQL

Overview | MySQL Control Panel Feature | Examples of SQL Statements | Quick Actions Advanced Queries | Table Properties | Table Select | Perl SQL Delete Example Perl SQL Insert Example | Perl SQL Update Example | Perl While Loop Example View Dump Database Schema | Using MySQL With CGI Scripts References and Tutorials | Back To "Manual - Table Of Contents"

Perl SQL Delete Example

Here we delete a record from the database using a DELETE statement.
 



# 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 = "DELETE FROM Phonebook WHERE (Id = 'BBBBB')";



# Prepare and execute the SQL query

$sth = $$dbh->prepare($$stmt) 

    || die "prepare: $$stmt: $DBI::errstr";

$sth->execute || die "execute: $$stmt: $DBI::errstr";



# DELETE does not return records



# Clean up the record set and the database connection

$sth->finish();

$dbh->disconnect();
 
Prices & PlansRegister a Domain NameOnLine ManualResources for WebmastersTestimonialsCheck Domain Name AvailabilityOur PoliciesAbout Our NetworkSetup FeesPayment CenterOrder FormPrices & PlansFrequently Asked Questions
Support | Contact | Home | FAQ's | Prices & Details | Order | Payment Center | Setup Fees | Our Network | Policy | Domain Name Registration  | On-Line Manual | Webmaster Resources | Testimonials | Domain Name Check |