How to convert phpobject or array to string for php database query? there are two functions: oci_fetch_object and oci_fetch_array (), which return the return values of the object and array types respectively. now I need a string type, how to convert? $ Results & nbsp; = & nbsp; "["; $ How to convert a php object or array to a string
There are two functions when querying a php database.
Oci_fetch_object and oci_fetch_array () return the return values of the object and array types respectively. now I need a string type. how can I convert it?
$ Results = "[";
$ Row = oci_fetch_array ($ stmt); <-oci_fetch_object can be used here.
$ Results + = ??? <-Here, if you convert the returned value $ row to the string type, I have tried (string ).
$ Results = "]";
------ Best solution --------------------
While ($ row = oci_fetch_array ($ stmt )){
$ Result [] = $ row;
}
$ Result = json_encode ($ result );
------ Other solutions --------------------
What you may need is json_encode.
------ Other solutions --------------------
Reference:
What you may need is json_encode.
I tried it. no...
In fact, my goal is to convert the returned values of oci queries into json strings.
------ Other solutions --------------------
According to your format, you want to convert the object or array to the json format ..
Upstairs positive solution, convert to json is json_encode, convert json to array is json_decode
If you want to splice it yourself, you can also. The array is converted to string, and implode is used directly.
------ Other solutions --------------------
Post the author'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, and the resulting $ results is 0 instead of a json Array. the query contains multiple returned values.
------ Other solutions --------------------
Reference:
While ($ row = oci_fetch_array ($ stmt )){
$ Result [] = $ row;
}
$ Result = json_encode ($ result );
After this change, the system prompts Cannot use a scalar value as an array in, and then $ result = ""
------ Other solutions --------------------
You deleted your original $ results =!
------ Other solutions --------------------
Reference:
You deleted your original $ results =!
Deleted, write only
While ($ row = oci_fetch_array ($ stmt )){
$ Result [] = $ row;
}
$ Result = json_encode ($ result );
And then return $ result.
$ Result [] = $ row; prompt Cannot use a scalar value as an array in
------ Other solutions --------------------
Reference:
You deleted your original $ results =!
Yes. I just found that there is a $ result definition at the beginning of the function. just delete it.