how to get the column names and the values of them in select statment.
I have a packaze like this named ADB.pm -
package ADB;
-
-
use DBI;
-
-
@ISA = ('Exporter');
-
@EXPORT_OK = ("Connection_check", "new","select_db","insert_db","delete_db","update_db");
-
-
sub new
-
{
-
my $class = shift;
-
my $self = {
-
_pf => shift,
-
_db => shift,
-
_host => shift,
-
_port => shift,
-
_user => shift,
-
_pass => shift
-
};
-
$dbh = Connection_check($self);
-
#$self->{_dbh} = $dbh;
-
bless $self, $class;
-
return $self;
-
}
-
-
sub Connection_check {
-
my($self ) = @_;
-
$dsn = "DBI:$self->{_pf}:$self->{_db};$self->{_host};$self->{_port}";
-
#$dsn = "DBI:mysql:database=$self->{_db};host=$self->{_host};port=$self->{_port}";
-
$dbhc = DBI->connect($dsn,$self->{_user},$self->{_pass})or die "Unable to connect: $DBI::errstr\n";
-
return ($dbhc)
-
}
-
-
### Retrieving the Rows ########
-
-
sub select_db{
-
my ($obj,$sel) = @_;
-
my $selnew = $dbh->prepare($sel);
-
$selnew->execute or die "Unable to connect: $DBI::errstr\n";
-
my @AoA;
-
my @FinArr;
-
while (@AoA = $selnew->fetchrow_array)
-
{
-
push @FinArr, [@AoA];
-
}
-
-
return @FinArr;
-
}
-
and perl file adb.pl like this -
#!/usr/bin/perl
-
-
use DBI;
-
use DBD::mysql;
-
use Utils::ADB;
-
-
-
$object = new ADB( "mysql","adb", "192.168.106.218", 3306, "root", "root");
-
-
my @records = $object -> select_db ("select * from users");
-
-
foreach $recRef (@records) {
-
print join (" ", @$recRef),"\n";
-
}
-
-
print "\n \n";
-
when i execute adb.pl it displays the table results blidly. i need to get the column names also with the respective values. Can u please tell me which modification i need to do in the code
results what i am getting are like this
1 admin admin 1 3 3
2 demouser 111111 1 1 1
i want the column names to be print for them.
3 3042
You aren't really going to be able to retrieve the column names from the select statement. Instead, you are going to have to do another db query statement to do either a "describe <tablename>" or a "show columns from <tablename>". They both do the same thing. You can then write a bit of code to parse out the column names so you can print them before your data is printed.
Regards,
Jeff
I would suggest that you define the table names rather than using the *. This way you are only getting the data from the columns you need.
--Mork
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Wiebke Pätzold |
last post by:
Hi all!
I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in...
|
by: Shino |
last post by:
Hi,
Can anyone help with this error: "ORA-00904: invalid column name"?
Thanks!
SQL> create view PPFa as
2 SELECT L.UserID AS LecID, U.Name, U.Email, I.IntakeID, S.UserID
AS StudID
3 FROM...
|
by: Sanjay Minni |
last post by:
What is the datatype to be used
for Primary Key columns for most
optimised access given that
- There will be a single column primary key only
- The values will only be integers (but as...
|
by: Colleyville Alan |
last post by:
I am trying to turn a short and fat (63 columns) table into one that is tall
and skinny (7 columns). Basically, I am trying to create a "reverse
crosstab" using a looping structure in VBA along...
|
by: Joe |
last post by:
Hi All,
I am new to using the Access DB and I need some help if someone
is able to give it to me. What I want to do is get the names of
the columns of certain tables. Not the data in the table...
|
by: Scot L. Harris |
last post by:
Currently using Postgresql 7.2.4-5.80 with php 4.2.2.-8.0.8 on a redhat
8.0 system.
I am writing some php scripts where I want to generate a list of the
column names in a particular table that...
|
by: Charleees |
last post by:
Hi all,
I have a DataGrid with Template Columns.....
There are LAbels,Linkbuttons in the Single Row..
I have to set the Constant Column width for those Template Columns in
Grid...
Wat...
|
by: Mike S |
last post by:
Hi all,
A (possibly dumb) question, but I've had no luck finding a definitive
answer to it. Suppose I have two tables, Employees and Employers, which
both have a column named "Id":
Employees...
|
by: RichardR |
last post by:
I have a webpage which has a table that contains a column with several drop down boxes (<SELECT>). The contents of the drop down boxes are dynamically populated so I have no idea what the actually...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |