What fetchrow_array returns in scalar context is undocumented. $data1 = $sth->fetchrow_array(); is wrong. If you want to the first field, use ($data1) = $sth->fetchrow_array();