File: C:/xampp/htdocs/myapi/getSqlData.php
<?php
// Assuming your PHP script interacts with a database or performs some other logic to generate data
// For this example, let's assume it generates a simple JSON response
// Sample data for demonstration purposes
$getCoS=$_GET['getCo'];
//$getPo=$_GET['getPo'];
$dotT = explode("_", $getCoS);////Measure uploa
$getCo=$dotT [0];
$getPo=$dotT [1];
//echo "getCo:".$getCo."_".$getPo;
$servername = "127.0.0.1";
$username = "root";
$password = "fredsql";
$DBNAME = "tvicheck-st";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//echo "Connected successfully";
if( !mysqli_select_db($conn, $DBNAME)) {
die ("無法選擇資料庫");
}
mysqli_query( $conn, "SET NAMES 'utf8'");
$querys = "select * from spotreport where (po='$getPo'and company='$getCo') ORDER BY id DESC LIMIT 1 ";
//echo $querys;
$results = mysqli_query($conn, $querys);
$num = mysqli_num_rows( $results);
//echo "<br>num:".$num;
if ($num > 0)
{
$row = mysqli_fetch_object($results);
$rgbS=$row->rgbS;
$rgbUp=$row->rgbUp;
$rgbLo=$row->rgbLo;
$stdL=$row->stdL;
$stda=$row->stda;
$stdb=$row->stdb;
$upL=$row->upL;
$upa=$row->upa;
$upb=$row->upb;
$LoL=$row->LoL;
$Loa=$row->Loa;
$Lob=$row->Lob;
}
//echo "<br> rgb code:".$rgbS."_".$rgbUp."_".$rgbS;
$data = array(
'rgbS' => $rgbS,
'rgbUp' => $rgbUp,
'rgbLo' => $rgbLo,
'stdL' => $stdL,
'stda' => $stda,
'stdb' => $stdb,
'upL' => $upL,
'upa' => $upa,
'upb' => $upb,
'LoL' => $LoL,
'Loa' => $Loa,
'Lob' => $Lob
);
// Encode the data as JSON
$jsonData = json_encode($data);
// Set the response header to indicate that the content is JSON
header('Content-Type: application/json');
// Output the JSON data
echo $jsonData;
?>