$lua = new Lua(); \<?php // CONNECT TO THE DATABASE $DB\_NAME = 'xxxxx'; $DB\_HOST = 'localhost'; $DB\_USER = 'xxxxx'; $DB\_PASS = 'xxxxx'; $mysqli = new mysqli($DB\_HOST, $DB\_USER, $DB\_PASS, $DB\_NAME); if (mysqli\_connect\_errno()) { printf("Connect failed: %s\n", mysqli\_connect\_error()); exit(); } $query = "SELECT \* FROM `news`"; $result = $mysqli-\>query($query) or die($mysqli-\>error.\_\_LINE\_\_); $json = array(); if(mysql\_num\_rows($result)) { while($row=mysql\_fetch\_row($result)) { $json[]=$row; } } echo 'Total results: ' . $result-\>num\_rows; echo json\_encode($json); mysql\_close($DB\_NAME); ?\>
So how will I connect to my app to the database
- You should not have a variable outside the php tags
2.You should put php file in website folder example
—hello.php
<?php
echo ‘hello’;
?>
—main.lua
network.request(“http://example.com/hello.php”, “GET”, function (e)
print(e.response)
end)
I get it now it’s kind of the same thing as android studio
network.request("http://example.com/hello.php", "GET", function (e) print(e.response) end) local function networkConnection( networkConnection ) if(network.request == true) then local storyboard = require "storyboard" storyboard.gotoScene("start") end end return scene
Is this code good to check if the app is connected or not ?