Web Hosting Support Manual
Web and Print Design - Web Hosting Support Manual

HOME

Account Overview

Getting Started

Control Panel 

FTP

Email Client Setup

CGI-bin

MySQL

 

HELPFUL TIPS

Reducing Spam

Preserving Server Space

Email Problems

MySQL

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


Perl SQL Update Example

Here we update a record in the database using an UPDATE 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.
UPDATE Addresses SET Last = 0 WHERE CustomerId = '$$customerId'
$stmt = "UPDATE Phonebook
         SET Telephone = '713-555-1212'
         WHERE Name LIKE '%Smith'";

# Prepare and execute the SQL query
$sth = $$dbh->prepare($$stmt) 
    || die "prepare: $$stmt: $DBI::errstr";
$sth->execute || die "execute: $$stmt: $DBI::errstr";

# UPDATE does not return records

# Clean up the record set and the database connection
$sth->finish();
$dbh->disconnect();
 

Copyright © 2000-2004 All rights reserved, Web and Print Design trading as www.webandprint.com.au