How to convert phpobject or array to string

Source: Internet
Author: User
Tags array to string convert json to array php database
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.