mysql - PHP PDO returning null column names -
i developing soap service in php.
have came across issue when retrieving results mysql.
problem
when retrieving results more columns specified in sql statement. affecting code when processing retrieved information. example when change fetch() fetchall(), can't process more 1 record. there way tell php or mysql return columns need , not return rubbish?
example code
$stmt2 = $pdo2->prepare("select `id`, `username`, `ip_address` padr_users `username` :username"); $stmt2->bindparam(':username',$searchparam, pdo::param_str, 20); $stmt2->execute(); $tmp = $stmt2->fetch(pdo::fetch_assoc); $response->return = var_export($tmp, true); this produce:
object(stdclass)#4 (1) { ["return"]=> string(193) "array ( 'id' => '19', 'username' => 'batman2', 'ip_address' => '192.168.0.1' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '' . "\0" . '', )" } before call mysql tried using these:
$pdo2->setattribute(pdo::attr_errmode, pdo::errmode_exception); $pdo2->setattribute(pdo::attr_oracle_nulls, pdo::null_natural); however doesn't make slightest difference.
note
have left intentionally fetch() , not fetchall() eliminate possibility implementation of fetchall() have influenced results.
you retrieving 3 columns. however, ip address has null data @ end of it. can tell concatenation operator between strings:
'ip_address' => '192.168.0.1' . "\0" . '' . "\0" . '' . "\0" . '' ^ ^ ^ ^ ^ ^
Comments
Post a Comment