Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 12. Perl API > last_insert_id( ) - Pg. 208

@$store; print "$store_name\n $address\n$city, $state\n $telephone\n\n"; foreach my $book (@$books){ my ($title, $publisher, $pub_year, $store, $qty) = @$book; if($store ne $store_id) { next; } print "$title ($publisher $pub_year) $qty\n"; } } exit; To save space, I left out the opening lines for the script, because they are the same as in the previous script. In the first SQL statement here, we're selecting the store information. With the fetchall_arrayref( ) method, we're storing the reference for the data in $stores . If we were to print out this variable, we would see only a long number and not the actual data. Although an SQL statement may retrieve many rows of data, all of the data will be stored in memory. Therefore, we can issue finish( ) and, as long as we don't disconnect from MySQL, we can issue another SQL statement. The next SQL statement selects the book inventory infor- mation. Once this has been collected, the connection to MySQL is terminated and we can begin displaying the data with the use of flow control statements. The first foreach statement loops through the data of each store and prints out the