Chapter 24 - MySQL



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 . All Rights Reserved.
The entire contents of this site is copyrighted and may not be reproduced for any purpose without prior written permission.
Table Of Contents:

Back To Index
|
Chapter 1
FTP Instructions

|
Chapter 2
SSH / Telnet

|
Chapter 3
Email Software Setup

|
Chapter 4
CGI Bin

|
Chapter 5
Secure Server

|
Chapter 6
Formmail

|
Chapter 7
Microsoft Front Page

|
Chapter 8
CGI Scripts

|
Chapter 9
COMING SOON

|
Chapter 10
COMING SOON

|
Chapter 11
Streaming Audio/Real Video

|
Chapter 12
File Manager

|
Chapter 13
Mail Manager

|
Chapter 14
Changing Passwords

|
Chapter 15
Site Statistics

|
Chapter 16
Network Tools

|
Chapter 17
FTP & Anon FTP

|
Chapter 18
SSH / Telnet

|
Chapter 19
Password Protect Directories

|
Chapter 20
Custom Error Pages

|
Chapter 21
MySQL

|
Chapter 22
Mime Types

|
Chapter 23
Crontab

|
Chapter 24
Entropy Chat

|
Chapter 25
Shopping Cart

|
Chapter 26
Search Engine Submission

|
Chapter 27
PGP

|
Chapter 28
Subdomains

|
Chapter 29
Archive Manager

|