12
ITN270.001 Wake Tech 1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II •Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

Embed Size (px)

Citation preview

Page 1: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 1

ITN270 Advanced Internet DatabasesLecture 11. The Perl DBI API - Part II

•Topics:– Perl DBI interface to MySQL

Page 2: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 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);

Page 3: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 3

Using fetchrow_array ()• Example:

Page 4: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 4

Using fetchall_arrayref()

• Example:

Page 5: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 5

Using selectall_arrayref($query)

• Example:

Page 6: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

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";}

Page 7: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

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};

Page 8: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

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:

Page 9: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 9

Using DBI in Web Application

• Example: Connection

Page 10: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 10

Using DBI in Web Application

• Example: Issue Query

Page 11: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 11

Using DBI in Web Application

• Example: Read & Display data

Page 12: ITN270.001 Wake Tech1 ITN270 Advanced Internet Databases Lecture 11. The Perl DBI API - Part II Topics: – Perl DBI interface to MySQL

ITN270.001 Wake Tech 12

Using DBI in Web Application

• Example: Close the connection