ITN Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL
ITN Wake Tech2 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);
ITN Wake Tech3 Using fetchrow_array () Example:
ITN Wake Tech4 Using fetchall_arrayref() Example:
ITN Wake Tech5 Using selectall_arrayref($query) Example:
ITN Wake Tech6 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";}
ITN Wake Tech7 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 = “ ”; $date = qq{ };
ITN Wake Tech8 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:
ITN Wake Tech9 Using DBI in Web Application Example: Connection
ITN Wake Tech10 Using DBI in Web Application Example: Issue Query
ITN Wake Tech11 Using DBI in Web Application Example: Read & Display data
ITN Wake Tech12 Using DBI in Web Application Example: Close the connection