5

Is there any way what-so-ever of SMS interacting with a mySQL database on my host site?

What if I make the SMS code reside there?

Is there any kind of web code (PHP, Perl, JavaScript, ect. that I can use to call from within the SMS code to perform SQL transactions (Selects, Inserts, Updates, Deletes, etc.)? i.e., can I create a library on the host side to be called from within SMS?

I have a website that has a mySQL backend and I would like to write a small app for my phone that will pretty much be a Mobile version of my site (less many features and graphics)

Thanx

Shane

sholmes
  • 53
  • 4
  • SMS code? Are you making a [WAP](http://en.wikipedia.org/wiki/Wireless_Application_Protocol) site for time travellers from 1997? It's not at all clear what you're asking here. – tadman Aug 22 '13 at 15:09
  • So you want to make an interface to a database, that you can access via SMS? – RandomSeed Aug 22 '13 at 15:21
  • 3
    He is refereing to Smart-Mobile-Studio(SMS) – Hackerman Aug 22 '13 at 15:42
  • Thanks Robert, yes, I am referring to Smart Mobile Studio which is evident in my tagging. – sholmes Aug 22 '13 at 18:59
  • @RandomSeed - I am not sure. I am kinda asking what my options are with interacting with mySQL from SMS. Does the code have to reside on my host, if so, are their built in options for interacting via JavaScript? If so, can I create something on the host side that I then can interact with from SMS - thanks – sholmes Aug 22 '13 at 19:03
  • I am wondering if I was to provide Web Services that connect to the mySQL database and return JSON data or XML would there be a way to call the services and receive the JSON and send JSON back? – sholmes Aug 24 '13 at 02:29

2 Answers2

7

You can't access mysql directly from a webbrowser (only when it has some kind of http interface with rest/json but no database server has this?). But of course you can call any http server, whether it is made with php or something else, rest, soap, json etc: you only need to know which url and maybe some "low level" javascript in a asm block.

For now, the easiest way would be to make a server in Delphi with RemObjects. In the SmartMobileStudio (SMS) IDE you can import the SOAP-like interface file, and all client side code (pascal) will be generated for you (with type safety)! :)

With some more effort you can make a SOAP server, but then you probably need to make some javascript code yourself (and you need a JS library with SOAP support).

In the next major release there will be support for node.js, which is a server side javascript server! Then it is very easy to acces mysql in node.js (or files etc, it has no webbrowser sandbox) and with socket.io you can easily access this node.js server (in the cloud if you wish) and send data with json. Nice thing with socket.io is that you can also push data to the client, because it supports websockets (realtime two-way tcpip communication over http).

André
  • 8,920
  • 1
  • 24
  • 24
7

You can also use XML to access your MySQL data :

Basically you would have a php file on your server like this one (named getuser.php) where you establish a connection to your database, submit a query and echo the result in whatever format you require (in this case a html formatted table).

=================================================================

/* Database config */

$db_host        = '....';
$db_user        = '....';
$db_pass        = '....';
$db_database    = 'symphony_kvc'; 

/* End config */

$q = intval($_GET['q']);

$con = mysqli_connect($db_host,$db_user,$db_pass,$db_database);
if (!$con)
  {
  die('Could not connect: ' . mysqli_error($con));
  }

mysqli_select_db($con,"$db_database");
$sql="SELECT * FROM comments WHERE id = '".$q."'";

$result = mysqli_query($con,$sql);

echo "<table border='1'>
<tr>
<th>name</th>
<th>url</th>
<th>email</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['url'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysqli_close($con);

?>

=================================================================

The SMS code looks like this

unit Form1;

interface

uses
  w3system, w3graphics, w3components, w3forms, w3fonts, w3borders,
  w3application, W3Elements, W3Button, w3memo, w3editbox, w3time, W3Label, W3Image;

type
  TForm1=class(TW3form)
  private
    { Private methods }
    {$I 'Form1:intf'}
  protected
    { Protected methods }
    procedure InitializeObject; override;
    procedure ShowClicked(Sender: TObject);
    procedure FinalizeObject; override;
    procedure StyleTagObject; reintroduce; virtual;
    procedure Resize; override;
    procedure GetMyData;
    Procedure HandleUpdate(Sender:TObject);
    MyData: String;
    Memo1: TW3Memo;
    Button1 :TW3Button;
    Edit1: TW3EditBox;
    FTimer: TW3Timer;
  end;

implementation

{ TForm1}

procedure TForm1.GetMyData;
begin
asm

 xmlhttp=new XMLHttpRequest();
 xmlhttp.onreadystatechange=function()
  {
  @MyData = '';
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    @MyData = xmlhttp.responseText;
    }
  }
  xmlhttp.open("GET","getuser.php?q=1",true);
  xmlhttp.send();
 end;  //asm

end;

procedure TForm1.HandleUpdate(Sender:TObject);
begin
  If MyData <> '' then begin               // populate controls soon as data received
    txtHint.InnerHTML := MyData;
    Memo1.Text := MyData;
    Button1.InnerHTML := MyData;
    Edit1.Text := StrAfter(MyData,'mailto:');
    FTimer.Enabled:=False;
    W3Image1.Visible := false;
  end;
end;

procedure TForm1.ShowClicked(Sender: TObject);
begin
  W3Image1.Visible := true;               //make spinner visible
  GetMyData;
  FTimer.OnTime:=HandleUpdate;            //wait until data fetched
  FTimer.Delay:=5;
end;

procedure TForm1.InitializeObject;
begin
      inherited;
      {$I 'Form1:impl'}
      W3Image1.LoadFromURL('res/spinner.gif');   //load spinner and set to invisible
      W3Image1.OnLoad :=
      procedure (Sender: TObject)
      begin
    W3Image1.Visible := false;
  end;

//create the 3 controls
  Edit1 := TW3EditBox.Create(Self);
  Edit1.SetBounds(30, 90, 400, 50);
  W3Label1.SetBounds(30, 50, 400, 50);  // title edit1

  Memo1 := TW3Memo.Create(Self);
  Memo1.SetBounds(30, 180, 400, 150);
  W3Label2.SetBounds(30, 142, 400, 50);  // title memo1

  Button1 := TW3Button.Create(Self);
  Button1.SetBounds(30, 520, 400, 150);

  W3Label3.SetBounds(30, 330, 500, 50);  // title divhtmlelement
  txtHint.SetBounds(30, 370, 400, 150);

  W3Button1.OnClick := ShowClicked;
  FTimer:=TW3Timer.Create;
end;

The above will display a button on a form, the other element on the form being a TW3DIVHtmlElement, a Memo and an EditBox. When clicked, the data will be fetched

Kudos w3schools, demo adapted from one of their articles

This works ok. See demo on www.lynkit.com.au/MySQL