Name

Msql::listfields

Synopsis

$fields = $db->listfields($table);

Msql::listfields takes as an argument the name of a table in the current database. It returns a reference to an object which contains the names of all of the fields, as well as some other information. This reference is known as a statement handle. You can access the information in a statement handle using any of the following functions: Msql::Statement::as_string, Msql::Statement::listindices (mSQL 2.0 only), Msql::Statement::numfields, Msql::Statement::table, Msql::Statement::name, Msql::Statement::type, Msql::Statement::isnotnull, Msql::Statement::isprikey, Msql::Statement::isnum, and Msql::Statement::length. If the table does not exist, the function returns an undefined value undef, and the error is placed in Msql::errmsg. See Msql::Statement::fetchhash for a technique that makes this function somewhat obsolete.

Example

use Msql;
my $db = Msql->connect;
$db->selectdb('mydata');

my $fields = $db->listfields('mytable');
warn ("Problem with 'mytable': " . $db->errmsg) if (not $fields);
# $fields is now a reference to all of the fields in the table 'mytable'.
print "mytable contains the following fields:\n";
print $fields->as_string;

Get MySQL and mSQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.