classes:general:dbsamples:perl_mysql
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| classes:general:dbsamples:perl_mysql [2020/10/23 22:18] – created localadmin | classes:general:dbsamples:perl_mysql [2021/09/17 22:27] (current) – localadmin | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Perl example for MySQL database connection ====== | ||
| + | |||
| + | < | ||
| use strict; | use strict; | ||
| use DBI qw(: | use DBI qw(: | ||
| Line 16: | Line 19: | ||
| $db_conn_string = " | $db_conn_string = " | ||
| - | # Connect to db on Hrothgar | + | # Connect to db |
| if ($conn = DBI-> | if ($conn = DBI-> | ||
| { | { | ||
| # Prepare and execute an SQL statement | # Prepare and execute an SQL statement | ||
| - | $sth = $dbh-> | + | $stmt = $conn-> |
| - | FROM table_name | + | FROM table_name |
| - | WHERE table_name.field=something" | + | WHERE table_name.field=something" |
| - | $sth-> | + | $stmt-> |
| - | # retrieve | + | # Retrieve |
| print "Query Output \n"; | print "Query Output \n"; | ||
| - | while(my $ref = $sth-> | + | while(my $ref = $stmt-> |
| print $ref-> | print $ref-> | ||
| print " | print " | ||
| Line 35: | Line 38: | ||
| else | else | ||
| { | { | ||
| - | # Couldn' | + | # Error! |
| } | } | ||
| + | </ | ||
classes/general/dbsamples/perl_mysql.1603491528.txt.gz · Last modified: by localadmin
