我正在使用ExpressJS和NodeJS构建应用程序,此应用程序的数据库将是postgresql。现在我实际上堆叠在API部分上。
所以我用PHP制作了一个简单的API,请看下面的代码
<?php
// Create connection
$con=new PDO('pgsql:host=localhost;port=5432;dbname=name;user=postgres;password=password');
// This SQL statement selects ALL from the table 'Locations'
$sql = "SELECT totalscore, datestamp_app FROM tests";
// Check if there are results
//if (
$result = $con->query($sql);
//{
// If so, then create a results array and a temporary one
// to hold the data
$resultArray = array();
$tempArray = array();
// Loop through each row in the result set
while($row = $result->fetch())
{
// Add each row into our results array
$tempArray = $row;
array_push($resultArray, $tempArray);
}
// Finally, encode the array to JSON and output the results
echo json_encode($resultArray);
//}
// Close connections
//pdo_close($con);
?>
因此,我可以使用SQL SELECT查询中的数据获取JSON
完美。
在我的应用程序中,我可以使用passportJS(Google,Facebook,本地令牌)为用户获取令牌
但我的问题是(并且我上周真的试图解决它)我应该用这个令牌关注选择查询,就像现在那样API.php执行我从测试表获取所有数据,放我的目标是仅为具体用户获取其令牌数据。
非常感谢任何帮助,谢谢你。