Just starting out? Need help? Post your questions and find answers here.
ebelouet
 
Posts: 7
Joined: Mon Apr 08, 2019 9:46 am

mysql

by ebelouet Mon Apr 08, 2019 9:49 am

Hi,

Is it possible to use msql data with spider basic ?

Sincerely
Eric
User avatar
Arbrakaan
 
Posts: 88
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva

Re: mysql

by Arbrakaan Mon Apr 08, 2019 10:17 am

Yep, you can communicate with mysql through PHP files on a webserver (With HTTPRequest) ( https://www.spiderbasic.com/documentation/http/index.html)

or you have SQLite (client side database) directly in SpiderBasic ( https://www.spiderbasic.com/documentation/database/index.html )
ebelouet
 
Posts: 7
Joined: Mon Apr 08, 2019 9:46 am

Re: mysql

by ebelouet Mon Apr 08, 2019 10:34 am

Thank you very much for that and we try this in few days
User avatar
Arbrakaan
 
Posts: 88
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva

Re: mysql

by Arbrakaan Wed Apr 10, 2019 9:47 am

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);

?>
saboteur
 
Posts: 19
Joined: Mon Jan 08, 2018 10:25 am

Re: mysql

by saboteur Wed Jun 26, 2019 11:36 am

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
User avatar
Peter
 
Posts: 605
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: mysql

by Peter Wed Jun 26, 2019 12:30 pm

saboteur wrote:but get the same error.

which error?
saboteur
 
Posts: 19
Joined: Mon Jan 08, 2018 10:25 am

Re: mysql

by saboteur Wed Jun 26, 2019 1:22 pm

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.
User avatar
Peter
 
Posts: 605
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1

Re: mysql

by Peter Wed Jun 26, 2019 2:24 pm

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
saboteur
 
Posts: 19
Joined: Mon Jan 08, 2018 10:25 am

Re: mysql

by saboteur Wed Jun 26, 2019 3:16 pm

Thanks Peter, i'd completely forgot about the debug interface on the browser :oops: - pointed me in the right direction.
saboteur
 
Posts: 19
Joined: Mon Jan 08, 2018 10:25 am

Re: mysql

by saboteur Thu Jun 27, 2019 8:52 am

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 :D

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
Return to Coding Questions

Who is online

Users browsing this forum: No registered users and 4 guests