How PHP object or array is converted to string
There are two functions when doing PHP database queries.
Oci_fetch_object and Oci_fetch_array (), return the return value of object and array type, respectively, I need a string type now, how to convert?
$results = "[";
$row = Oci_fetch_array ($stmt); <-here with Oci_fetch_object can also
$results + =??? <-here if you convert the return value $row to a string type, I tried (string) No
$results = "]";
------Optimal Solution--------------------
while ($row = Oci_fetch_array ($stmt)) {
$result [] = $row;
}
$result = Json_encode ($result);
------Other Solutions--------------------
What you might need is json_encode.
------Other Solutions--------------------
Citation: What
you might need is json_encode.
I tried, no ...
In fact, my purpose is to change the return value of the OCI query into a JSON string.
------Other Solutions--------------------
Look at your format, you want to convert object or array into JSON format.
Upstairs positive solution, converted to JSON is Json_encode,json to array is Json_decode
If you want to be able to splice yourself ah. Array into string, use implode directly
------Other Solutions--------------------
Post the landlord's data
------Other Solutions--------------------
$results = "[";
$usercount = 0;
$row = Oci_fetch_array ($stmt);
if ($row) {
$results + = $row;
$usercount + +;
}
while (1) {
$row = Oci_fetch_array ($stmt);
if (! $row) break;
$results + = "," + $row;
$usercount + +;
}
$results + = "]";
This is my code, the $results is 0 instead of a JSON array, where the query is a number of return values
------Other Solutions--------------------
Reference: while
($row = Oci_fetch_array ($stmt)) {
$result [] = $row;
}
$result = Json_encode ($result);
This changes the prompt cannot use a scalar value as an array in, and then $result= ""
------Other Solutions--------------------
You put your original $results = "["; Erase it!
------Other Solutions--------------------
Citation:
you put your original $results = "["; Erase it!
It's erased, only written.
while ($row = Oci_fetch_array ($stmt)) {
$result [] = $row;
}
$result = Json_encode ($result);
This section, and then back to $result.
$result [] = $row; hint cannot use a scalar value as an array in
------Other Solutions--------------------
Citation:
you put your original $results = "["; Erase it!
Yes, I just found out there's a $result definition at the beginning of the function, and it'll be erased.