Click to See Complete Forum and Search --> : [RESOLVED] "Use of uninitialized value" for database variable


yssirhc
05-13-2009, 10:23 AM
I have a web page that prints information from a database based on the query string variables. Sometimes the page loads just fine and other times it gives the message "Use of uninitialized value" for every single one of my database variables. The times it gives this message seem to be when there is info in the Description, Steps, and/or WorkAround fields, all of which are memos.

Is there something I'm doing wrong or missing from this code?


$bugID = $in{'ID'};
$user = $in{'user'};

### connect to database #####
$dbhandle = DBI->connect("DBI:ODBC:bugzdead") or &errorPage("Couldn't connect to database: " . DBI->errstr());

### get bug info #####
$sql = "SELECT B.Problem, B.Product, B.Version, B.Type, B.Severity, B.Description, B.Steps, B.WorkAround, B.SubmittedBy, S.Status, S.DateSubmitted, S.DateEdited, R.AverageRating FROM Bugs AS B, Status AS S, Rating AS R WHERE B.ID=S.BugID AND S.BugID=R.BugID AND ID=" . $bugID;
$query = $dbhandle->prepare($sql) or &errorPage("Couldn't prepare Select Bug Info query: " . $dbhandle->errstr());
$query->execute() or &errorPage("Couldn't execute Select Bug Info query: " . $query->errstr());

@row = $query->fetchrow_array();
$query->finish();

### database variables #####
$problem = $row[0];
$product = $row[1];
$version = $row[2];
$type = $row[3];
$severity = $row[4];
$description = $row[5];
$steps = $row[6];
$workAround = $row[7];
$submittedBy = $row[8];
$status = $row[9];
$dateSubmitted = $row[10];
$dateEdited = $row[11];
$averageRating = $row[12];

Sixtease
05-14-2009, 03:59 AM
After a quick read... Check the return value of $query->fetchrow_array();
from perldoc DBI
If there are no more rows or if an error occurs, then "fetchrow_array" returns an empty list. You should check "$sth->err" afterwards (or use the "RaiseError" attribute) to discover if
the empty list returned was due to an error.
@row = $query->fetchrow_array();
if (defined $query->err) {
# handle error
print $query->errstr;
}

yssirhc
05-14-2009, 11:19 AM
ok, so now I'm getting a message:
[Microsoft][ODBC Microsoft Access Driver]String data, right truncated on column number 6 (Description) (SQL-01004)

I don't really know what this means though.

I'm putting the data from the database into a table. and I assumed that the cell the data is being put into would expand on its own (increase its width and wrap the contents). Is this not the case, or am I interpreting this message wrong?

yssirhc
05-14-2009, 01:06 PM
nevermind.

I found a solution through google:
http://e-hon.blogspot.com/2008/04/today-i-got-next-error-when-i-tried-to.html

I just needed to add these 2 lines of code:

$dbhandle-> {'LongTruncOk'} = 1;
$dbhandle-> {'LongReadLen'} = 500;


:)

don't really know why though....is this a bug with the database driver?

thanks for the help!