mysql

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

mysql

Post by ebelouet »

Hi,

Is it possible to use msql data with spider basic ?

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

Re: mysql

Post 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 )
ebelouet
Posts: 21
Joined: Mon Apr 08, 2019 9:46 am

Re: mysql

Post by ebelouet »

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

Re: mysql

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

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

Re: mysql

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

Re: mysql

Post by Peter »

saboteur wrote:but get the same error.
which error?
saboteur
Posts: 27
Joined: Mon Jan 08, 2018 10:25 am

Re: mysql

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

Re: mysql

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

Re: mysql

Post by saboteur »

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

Re: mysql

Post 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 :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
Post Reply