questions about bind_param and mysql

questions about bind_param and mysql

am 28.01.2004 03:48:28 von smrtalec

I have a snippet of code below. I'm trying to use teh bind_param option to select multiple rows using a foreach loop. after doign some reading I realized this is supprted through DBD are there any special measures that I need to take to make bind_param work.



## select rows in table based on search strings - only works with or
foreach $search(@search_pat){
my $sth = $dbh->prepare ("SELECT str_no_addr, str_name_addr, cit_addr
FROM s3a_inglewood_project_info
WHERE * LIKE ?;") or err_trap("failed to prepare statement\n");
$sth->bind_param(1,$search);

## exicute and fetch selected rows
$sth->execute or
err_trap("failed to execute statement\n");
}
my $array_ref = $sth->fetchall_arrayref();


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: questions about bind_param and mysql

am 28.01.2004 20:40:00 von smrtalec

> Should work, as long as your parameters are all strings. With numbers
> you currently need to specify the type (for example DBI::INTEGER or
> similar, written from memory) as a third parameter.


do I need to specify the DBD module in addition to DBI ? After reading the module info on CPAN it seemed to offer two options one just specifying DBI then anothe where you encoded the connection info using DBD then used DBI->connect to connect.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: questions about bind_param and mysql

am 28.01.2004 20:40:00 von smrtalec

> Should work, as long as your parameters are all strings. With numbers
> you currently need to specify the type (for example DBI::INTEGER or
> similar, written from memory) as a third parameter.


do I need to specify the DBD module in addition to DBI ? After reading the module info on CPAN it seemed to offer two options one just specifying DBI then anothe where you encoded the connection info using DBD then used DBI->connect to connect.


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: questions about bind_param and mysql

am 29.01.2004 03:56:27 von smrtalec

I'm attempting a search for multiple strings using the bind_param option. My understanding is the server will flag each string then after each string has been selected and exicuted I can then do a fethall_array. However the the results only include the last string searched. any ideas. an example query woudl be like [qw/%7th% %8th%/] only values for %8th% are returned. help

++++++++++++++++++++++++++++++++++++++++

### extract search pattern, and values and seperate into veriables
my @search_pat = @_;
my $pat = $search_pat[0];
shift (@search_pat);
my $svalue;
my $dbh = connect_try("rowan","5340brig");
my $sql = "SELECT str_no_addr, str_name_addr, cit_addr FROM s3a_inglewood_project_info WHERE str_name_addr LIKE ?;";
## select rows in table based on search strings - only works with or
my $sth = $dbh->prepare ($sql) or err_trap("failed to prepare statement\n");
foreach $svalue (@search_pat){

$sth->bind_param( 1, $svalue);
$sth->execute or err_trap("failed to execute statement\n");
}
my $array_ref = $sth->fetchall_arrayref();

# place field names on top
unshift @$array_ref, [ 'id no.', 'street no.', 'street name', 'city' ];
# place search values in with everything to make sure i'm getting ligit values
unshift (@$array_ref, @search_pat);

$dbh->disconnect or err_trap("failed to disconnect at get_date statement\n");
gen_table ($array_ref);
}


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org

Re: questions about bind_param and mysql

am 29.01.2004 03:56:27 von smrtalec

I'm attempting a search for multiple strings using the bind_param option. My understanding is the server will flag each string then after each string has been selected and exicuted I can then do a fethall_array. However the the results only include the last string searched. any ideas. an example query woudl be like [qw/%7th% %8th%/] only values for %8th% are returned. help

++++++++++++++++++++++++++++++++++++++++

### extract search pattern, and values and seperate into veriables
my @search_pat = @_;
my $pat = $search_pat[0];
shift (@search_pat);
my $svalue;
my $dbh = connect_try("rowan","5340brig");
my $sql = "SELECT str_no_addr, str_name_addr, cit_addr FROM s3a_inglewood_project_info WHERE str_name_addr LIKE ?;";
## select rows in table based on search strings - only works with or
my $sth = $dbh->prepare ($sql) or err_trap("failed to prepare statement\n");
foreach $svalue (@search_pat){

$sth->bind_param( 1, $svalue);
$sth->execute or err_trap("failed to execute statement\n");
}
my $array_ref = $sth->fetchall_arrayref();

# place field names on top
unshift @$array_ref, [ 'id no.', 'street no.', 'street name', 'city' ];
# place search values in with everything to make sure i'm getting ligit values
unshift (@$array_ref, @search_pat);

$dbh->disconnect or err_trap("failed to disconnect at get_date statement\n");
gen_table ($array_ref);
}


--
MySQL Perl Mailing List
For list archives: http://lists.mysql.com/perl
To unsubscribe: http://lists.mysql.com/perl?unsub=gcdmp-msql-mysql-modules@m .gmane.org