foxy88
March 21, 2023, 2:30pm
1
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”
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…
foxy88
March 21, 2023, 3:25pm
3
PHP.
“Default” is the JSON name of the array. However, in the DB is a TEXT type.
So, you’re trying to save an array to a text column…
foxy88
March 21, 2023, 3:31pm
5
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.
foxy88
March 21, 2023, 3:39pm
8
Yes, I know all of this… The problem is how to do it with Wappler and dynamically…
If i’m following this right you have a query that will return an array non comma separated and you want them to be made into a comma separated array?
For this you could use the join formatter:
[Screenshot 2022-03-23 at 19.03.03]
To use join simply select the query returning the array, then add the join formatter select a comma as the separator and then the property you want to repeat in this case category_name
Sorry if I misunderstood my friend, just trying to help
1 Like
foxy88
March 21, 2023, 3:51pm
11
@famousmag , none of them work for me.
Thank you anyway; I appreciate your help!
1 Like
Share a screenshot of the GetConfigDetails action please… And the DB insert also
foxy88
March 21, 2023, 4:13pm
13
This is the schema of the API Action:
This is the Database Insert:
…basic.inputs[$index ].default}}
foxy88
March 21, 2023, 4:29pm
15
No, it does not work.
I have to keep that number fixed as it is the 6th JSON object in the schema.
Teodor
March 21, 2023, 5:54pm
16
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.