Upload
mildred-roberts
View
212
Download
0
Embed Size (px)
Citation preview
ITN270.001 Wake Tech 1
ITN270 Advanced Internet DatabasesLecture 11. The Perl DBI API - Part II
•Topics:– Perl DBI interface to MySQL
ITN270.001 Wake Tech 2
Related issues for DBI with MySQL
• Handling Queries That Return a Results Set– Working with complete Sets
• use matrix contains to contain all the information
• Example:
– fetchrow_array ()
– fetchrow_arrayref()
– selectall_arrayref($query);
ITN270.001 Wake Tech 3
Using fetchrow_array ()• Example:
ITN270.001 Wake Tech 4
Using fetchall_arrayref()
• Example:
ITN270.001 Wake Tech 5
Using selectall_arrayref($query)
• Example:
ITN270.001 Wake Tech 6
Checking for NULL values
• Example:if (!defined ($col_val)) {print "NULL\n";}
elsif ($col_val eq " ") {print "empty string\n”;}
elsif ($col_val == 0) {print "zero\n";}
else { print "other\n";}
ITN270.001 Wake Tech 7
Quoting Issues
• Example:– Double Quotes vs. Single Quotes
• “SELECT * FROM member WHERE id = $var”
• ‘SELECT * FROM member WHERE id = $var’
– Using qq{ }, qq( ), or qq/ /• $date = “2002-09-16”;
• $date = qq{2002-09-16};
ITN270.001 Wake Tech 8
Binding Query Results To Script Variable
• It allows to parameterized the output by retrieving column values into variable automatially when fetching a row with out having to assign values to the variables yourself
• Example:
ITN270.001 Wake Tech 9
Using DBI in Web Application
• Example: Connection
ITN270.001 Wake Tech 10
Using DBI in Web Application
• Example: Issue Query
ITN270.001 Wake Tech 11
Using DBI in Web Application
• Example: Read & Display data
ITN270.001 Wake Tech 12
Using DBI in Web Application
• Example: Close the connection