Account Overview - Getting Started - Control Panel Overview - Chapter 1 FTP Software Setup
Chapter 2 SSH / Telnet Setup - Chapter 3 Email Software Setup - Chapter 4 CGI-Bin - Chapter 5 Secure Server
Chapter 6 FormMail - Chapter 7 MS FrontPage - Chapter 8 CGI Scripts - Chapter 9 ASP - Active Server Pages
Chapter 10 JSP - Java Server Pages - Chapter 11 PHP - Chapter 12 Real Audio/Real Video
Chapter 13 File Manager - Chapter 14 Mail Manager - Chapter 15 Changing Passwords - Chapter 16 Site Statistics
Chapter 17 Network Tools - Chapter 18 FTP Manager - Chapter 19 Backup Manager - Chapter 20 Password Protect Directories
Chapter 21 Custom Error Pages - Chapter 22 MySQL & PhpMyAdmin - Chapter 23 Mime Types - Chapter 24 CronTab
Chapter 25 Entropy Chat - Chapter 26 Akopia Shopping Cart - Chapter 27 Search Engine Submission
Chapter 28 PGP & PGP Mail - Chapter 29 Subdomains

Chapter 22 - 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();
Back To Top






©Copyright 1998 Web Host It. All Rights Reserved.