I went into Control panel/ODBC/ and selected Microsoft Access driver and identified the source name.
I was looking at a previous post here and many things appear to be similar to my requirements.
1. Add dbi inclusion. (pretty straight forward, like an “include” in C or “import” in Java
Expand|Select|Wrap|Line Numbers
- use DBI;
- $::db_host = 'localhost';
- $::db_name = 'KTC.mdb';
- $::db_user = 'root';
I’m not sure what the db_user=’root’ statement does?
2.Add database connection hardcoding the user name and password. (use the DBI connect call and store the handle)
This is somewhat confusing because there are no passwords on our database. I am also using access not mysql. DBI:mysql:host= ??
Expand|Select|Wrap|Line Numbers
- # $::db = DBI->connect(
- # "DBI:mysql:host=$::db_host;database=$::KTC.mdb",
- # $::db_user) || die $DBI::errstr;
Expand|Select|Wrap|Line Numbers
- my $stm= $::db->prepare("SELECT ProductName, ProductDescription, UnitsInStock, UnitPrice FROM Products WHERE ProductID = $productID ORDER BY ProductID");
- $stm->execute || die $::db->errstr;
- my $LST = $stm->fetchall_hashref('ProductID');
5. Code the loop by fetching an array from the statement handle. (use “fetchrow_array()”, will return records from database into an array “@product”, there are also other ways to do this, could return a hash)
6. Display the records. (students often get confused with this. You need to access the indices of the array to display in the table. Each index corresponds to the column name in the select statement of your query. The syntax to grab an index of an array for this project in perl is (“$product[x]” where x is a number pertaining to the column name, will map to product information)
I haven’t even looked at these requirements yet.
7. Disconnect database.
Expand|Select|Wrap|Line Numbers
- $rc = $dbh->disconnect();