Array to string conversion error

Hello,

I am executing an API Action following a Database Insert within a Repeat cycle.

However, I get this error message in the browser:

{"code":0,"file":"C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\db\\Connection.php","line":141,"message":"Array to string conversion","trace":"#0 [internal function]: exception_error_handler(2, 'Array to string...', 'C:\\\\xampp\\\\htdocs...', 141)\n#1 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\db\\Connection.php(141): PDOStatement->bindParam(2, Array, 2)\n#2 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\modules\\dbupdater.php(164): lib\\db\\Connection->execute('INSERT INTO `sc...', Array, false, 'scandetails')\n#3 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(204): modules\\dbupdater->insert(Object(stdClass), 'insert', Array)\n#4 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(176): lib\\App->execSteps(Object(stdClass))\n#5 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(144): lib\\App->execSteps(Array)\n#6 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\modules\\core.php(69): lib\\App->exec(Object(stdClass), true)\n#7 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(204): modules\\core->repeat(Object(stdClass), 'repeat', Array)\n#8 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(176): lib\\App->execSteps(Object(stdClass))\n#9 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(144): lib\\App->execSteps(Array)\n#10 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(133): lib\\App->exec(Object(stdClass), false)\n#11 C:\\xampp\\htdocs\\testapp\\dmxConnectLib\\lib\\App.php(111): lib\\App->exec(Object(stdClass))\n#12 C:\\xampp\\htdocs\\testapp\\dmxConnect\\api\\GetConfigDetails.php(8): lib\\App->define(Object(stdClass))\n#13 {main}"}

Basically, I want to insert in the database the values “7918” and “7856”

image

In this format: [7918, 7856].

How can I do that?

Thank you.

Hey,

PHP/ MySQL?

What is your db table structure (what type is this field “default” )?

A screenshot of your action in order to understand how are you trying to accomplish it…

PHP.

“Default” is the JSON name of the array. However, in the DB is a TEXT type.

image

So, you’re trying to save an array to a text column…

Yes, correct.

That is what I want to achieve - saving that array as text in the following format: [abc, def].

this is not just a format… this is an array type of data.
This column (default that is TEXT type) will keep the data and you have to pull them out from in some way…
I am not so good on JSON but found this, maybe it can help you solve it.

How to store array data type in MySQL | sebhastian

Yes, I know all of this… The problem is how to do it with Wappler and dynamically…

Sorry if I misunderstood my friend, just trying to help

1 Like

@famousmag, none of them work for me.

Thank you anyway; I appreciate your help! :wink:

1 Like

Share a screenshot of the GetConfigDetails action please… And the DB insert also

This is the schema of the API Action:

image

This is the Database Insert:

…basic.inputs[$index].default}}

No, it does not work.

I have to keep that number fixed as it is the 6th JSON object in the schema.

Well you need to use the join formatter in server connect for the insert value if you want to join the array values to a string.