mysql - PHP bind_result and fetch multiple rows (array) -
mysql - PHP bind_result and fetch multiple rows (array) -
i'm new php , mysql. i'm trying create rest api php, , because server doesn't have mysqlnd
installed, have utilize bind_result
, fetch
.
$stmt = $this->conn->prepare("select * d d.id = ?"); $stmt->bind_param("i", 1); if($stmt->execute()){ $stmt->bind_result($a, $b, $c); $detail = array(); while($stmt->fetch()){ $detail["a"] = $a; $detail["b"] = $b; $detail["c"] = $c; } $stmt->close(); homecoming $response; } else { homecoming null; }
above code works can homecoming 1 line of info @ time.
for illustration if statement return:
a b c 1 test test 1 test1 test1
it returns
a: 1 b: test1 c: test1
where supposed be:
{ a: 1 b: test c: test }, { a: 1 b: test1 c: test1 }
you're overwritting them, instead:
$detail = array(); while($stmt->fetch()) { $temp = array(): $temp["a"] = $a; $temp["b"] = $b; $temp["c"] = $c; $detail[] = $temp; }
or straight appending them dimension:
$detail = array(); while($stmt->fetch()) { $detail[] = array('a' => $a, 'b' => $b, 'c' => $c); // ^ add together dimension }
php mysql
Comments
Post a Comment