0

I have a query in which I insert data with json_encode(), and I am trying to receive that data with json_decode(), however, I get an error message that is something like this:

stripslashes() expects parameter 1 to be string, array given in

I have this database table that has about 20 fields. So, this is how I am trying to retrieve the results:

if($q->rowCount() > 0) {
            while($r = $q->fetch(\PDO::FETCH_ASSOC)) {
                $array[] = $r;
            }
            return $array;
        }

The results come back fine, but I can't seem to get pass this stripslashes error. I've also tried json_decode($json_string, true); with no luck. I am hoping that someone can point me into the right direction.

3
Contributors
7
Replies
27
Views
4 Years
Discussion Span
Last Post by joshmac
0

I should also mention that I am using a framework and my values are formatted like this in the view:

<?php echo clean($this->prog[0]['startDate']);?>
0

Hi,

For my own personal experimentation potential, what is the purpose or benefit of having the data inserted to db as json encoded Vs. the Conventionals?

0

There is none. I've been working for 12 hours, and I can't even think straight. I've tried json and serialized, and both give me the same error. If there is an easier way, please enlighten me.

0

And if my conventional you mean this:

explode(",",$this->prog[0]['acadYearKey'])

I've tried that also, and I still get the same error message.

0

Unless you're storing this data purely in order to pass to a javascript, I can't see the purpose - even then I find it difficult to fathom.

Data in a DB, usually needs to be able to be searched, filtered or sorted (there are exceptions). Cobbling it all together in json format or some sort of stringified array just seems wrong. Which framework are you using? Why is it using stripslashes? There should be no need to use clean with mysqli parameterized binding?

0

And that is what I don't understand. I am not using stripslashes, but it is giving me that error message.

0

Actually, you're right. It was being used. I switched from mysqli to pdo and that wasn't clean up in one of my helpers.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.