APC Action Applications - Home Page

Frequently Asked Questions v2

 

Sure - here is a little example that shows how to write a little Perl program to execute and return a SQL string.

#!/usr/bin/perl -w


# this script demonstrates how to use perl to look at the
# mysql database for a slice.
# This particular script looks some of the attributes of a slice's fields


# EDIT NEEDED: set these variables!
# $slice_id $user $password $database $host


# create connection to mysql, using perl DBI module
use DBI;
$dsn = "DBI:mysql:$database:$host";
$dbh = DBI->connect($dsn, $user, $password);


# convert a Hexadecimal input into a packed string
$p_slice_id = pack 'H*', $slice_id;


# create a SQL statement handle, and prepare a template.
# Templates make quoting easier.
my $sth_p = $dbh->prepare(
q{ SELECT id, name, feed, input_show_func from field where slice_id = ? }
) or die $dbh->errstr;


# run the statement, using the packed sliceid, and print the results
$sth_p->execute($p_slice_id) or die $dbh->errstr;
DBI::dump_results($sth_p);

Last Edit: Aug 17 2011

<aafaq id=1709> ~ToDo: 1709 How can I look at the database with Perl? </aafaq> 

This FAQ interface was developed by Jason at Commons.ca

APC: Internet and ICTs for social justice and development APC ActionApps is a free software content management system initiated by the Association for Progressive Communications (APC)
APC - Internet and ICTs for social justice and development