Page 1 of 2
mysql
Posted: Mon Apr 08, 2019 9:49 am
by ebelouet
Hi,
Is it possible to use msql data with spider basic ?
Sincerely
Eric
Re: mysql
Posted: Mon Apr 08, 2019 10:17 am
by Arbrakaan
Yep, you can communicate with mysql through PHP files on a webserver (With HTTPRequest) (
https://www.spiderbasic.com/documentati ... index.html)
or you have SQLite (client side database) directly in SpiderBasic (
https://www.spiderbasic.com/documentati ... index.html )
Re: mysql
Posted: Mon Apr 08, 2019 10:34 am
by ebelouet
Thank you very much for that and we try this in few days
Re: mysql
Posted: Wed Apr 10, 2019 9:47 am
by Arbrakaan
SpiderBasic code :
Code: Select all
Procedure HttpGetEvent(Success, Result$, UserData)
If Success
Debug Result$
Else
Debug "HTTPRequest(): Error"
EndIf
EndProcedure
Procedure PostProject(id,name.s)
params.s = "?&id="+Str(id)+"&name="+name
HTTPRequest(#PB_HTTP_Post, "PostData.php", params.s, @HttpGetEvent())
EndProcedure
PostProject(184,"SpiderBasic")
PHP file (
PostData.php ) :
Code: Select all
<?php
$id = isset($_POST['id']) ? $_POST['id'] : '';
$name = isset($_POST['name']) ? $_POST['name'] : '';
var_dump($id);
var_dump($name);
?>
Re: mysql
Posted: Wed Jun 26, 2019 11:36 am
by saboteur
Sorry to revive this thread.
I've tried the above method - deployed it to my webserver and all i get is a blank screen with a blue background.
I've also tried changing the line :
Code: Select all
HTTPRequest(#PB_HTTP_Post, "PostData.php", params.s, @HttpGetEvent())
to
Code: Select all
HTTPRequest(#PB_HTTP_Post, "http://myserver/PostData.php", params.s, @HttpGetEvent())
but get the same error.
Any ideas where i'm going wrong.
cheers
Re: mysql
Posted: Wed Jun 26, 2019 12:30 pm
by Peter
saboteur wrote:but get the same error.
which error?
Re: mysql
Posted: Wed Jun 26, 2019 1:22 pm
by saboteur
Hi Peter,
Sorry for the lack of info.
The SB program throws 'HTTPRequest(): Error' in the debug window when compiled from within SB, whicj is why i pointed directly to the PHP on the server.
When I compile it and deploy it to my server I just get a blank default blue background and nothing else.
I'm not a PHP/ajax virgin, but don't understand CGI at all, but would really benefit from a simple demo of a SB getting data to/from a mariadb/mysql database on a server cos i really can't seem to get my head around how this works in real time.
Anyway thanks for looking.
Re: mysql
Posted: Wed Jun 26, 2019 2:24 pm
by Peter
If you open the developer console of your browser (usually by pressing the F12 key) and then switch to the Network tab, you will see a more meaningful error message.
Greetings ... Peter
Re: mysql
Posted: Wed Jun 26, 2019 3:16 pm
by saboteur
Thanks Peter, i'd completely forgot about the debug interface on the browser
- pointed me in the right direction.
Re: mysql
Posted: Thu Jun 27, 2019 8:52 am
by saboteur
First up thanks to everyone for the help so far.
I now have a working form that will display requested information upon a button click and getting the data via a PHP script
So my next question is what is the best way to parse the data being returned back.
I've never used JSON although i've seen it referenced quite a bit on the forum, but don't quite see how it fits into parsing the retuned data ?
i tried modifying an example in SB but it's not working and wonder if anyone here can offer some advice
Code: Select all
LVAR_text.s
If ParseJSON(0, Chr(34) + Result$ + Chr(34))
For i = 0 To JSONArraySize(JSONValue(0)) - 1
LVAR_text + GetJSONString(GetJSONElement(JSONValue(0), i)) + #CRLF$
Next i
Else
JSONErrorMessage()
EndIf
SetGadgetText(GVAR_a, Result$)
i'm actualy echo'ing the data back through the PHP script so this may not be the best way to acheive this.
Thanks