Greetings,
I've finally connected to the database OK, I was having problems
before but that was some mis-communication between me and the
webserver host, my bad.
Now that I'm connected, I'm getting the following error:
DBD::ODBC::db prepare failed: [Microsoft][ODBC SQL Server Driver][SQL
Server]Invalid object name 'tblClient'. (SQL-S0002)
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not
be prepared. (SQL-37000)(DBD: st_prepare/SQLPrepare err=-1) at
D:\home\LPJ861\cgi-bin\dbsearch.pl line 75.
I know that the select statement works, I've ran it in SQL Query
Analyzer and it printed out the results no problem.
If anyone can point me to the error that I'm having or a way to fix
it, I'd be greatly appreciative.
Ryan
Code is as follows:
#!/usr/local/bin/perl
use strict;
use CGI qw(:standard);
use Data::Dumper;
use DBI;
#Retreiving variable information
my $keyWord = param("keyWord");
my $Area = param("cboArea");
my $Municipality = param("cboMun");
my $City = param("cboCity");
my $Category = param("cboCategory");
#Variable declarations
my $userID = "userID";
my $password = "password";
#Connects to the Database
my $dbh = DBI->connect( "dbi:ODBC:beHealthyManitoba", $userID,
$password,
{RaiseError => 1, PrintError => 1, AutoCommit => 1})
or die "Unable to connect: " . $DBI::errstr . "\n";
#Tells if database is defined
print "\$dbh is ", (defined($dbh) ? "defined" : "undefined"), "\n";
#Prepares the select statement
my $sql = "SELECT FirstName, LastName, Organization, Address, Phone,
Website FROM tblClient ";
#keyWord entered
if ($keyWord ne "")
{
$sql = "$sql WHERE FirstName LIKE '%$keyWord%'";
$sql = "$sql OR LastName LIKE '%$keyWord%'";
$sql = "$sql OR Address LIKE '%$keyWord%'";
$sql = "$sql OR CategoryKey LIKE '%$keyWord%'";
$sql = "$sql OR Organization LIKE '%$keyWord%'";
$sql = "$sql OR Phone LIKE '%$keyWord%'";
$sql = "$sql OR AreaKey LIKE '%$keyWord%'";
$sql = "$sql OR MunicipalityKey LIKE '%$keyWord%'";
$sql = "$sql OR CityKey LIKE '%$keyWord%'";
$sql = "$sql OR Website LIKE '%$keyWord%'";
}
#Area selected
if ($Area ne "")
{
$sql = "$sql WHERE AreaKey = $Area";
}
#Municipality selected
if ($Municipality ne "")
{
$sql = "$sql AND Municipality = $Municipality";
}
#City selected
if ($City ne "")
{
$sql = "$sql AND City = $City";
}
#Category selected
if ($Category ne "")
{
if ($sql =~ m/WHERE/i)
{
$sql = "$sql AND CategoryKey = $Category";
}
else
{
$sql = "$sql WHERE CategoryKey = $Category";
}
}
#End select Statement
print $sql;
#prepares select statement
my $pre = $dbh->prepare("$sql");
#Executes the select statement
#Disconnect from Database and exit
$pre->finish;
$dbh->disconnect;
exit