-1

是否可以在 Spotify 应用程序中连接到 mysql 数据库?我将 mysql 添加到所需的权限,但它显示了整个 php 代码。由于搜索功能,我想添加mysql。

4

2 回答 2

4

Spotify 应用程序不支持 PHP。官方仅支持 HTML、CSS 和 JavaScript。(来源

也许您可以在您的服务器上创建一个可以使用 JavaScript 访问的后端。

于 2012-01-11T02:59:14.113 回答
2

在你的 manifest.json 添加

“必需的权限”:[
        "http://your.site.com",
        "http://ajax.googleapis.com",  
           ]

在您的应用中添加

  $.getJSON("http://your.site.com/get_variable.php", { "variable": variable },
    function(data) {
      //do something with the returned data
    }
  ).error(function() { console.log("error getting variable"); });

在您的服务器上添加一个执行您的 sql 的文件 get_variable.php

$con = mysql_connect("localhost","user_name","password");

if (!$con){
  die('Could not connect: ' . mysql_error());
}
$db_selected=mysql_select_db("database_name", $con);

if (!$db_selected){
  die ("Can\'t use database_name : " . mysql_error());
}

$variable = $_GET["variable"];
$sql = "your sql using $variable" 
$result = mysql_query($sql);
$search_results=array(); 
while($row = mysql_fetch_array($result)){
  //add data from $row into $search_results
}
echo json_encode($search_results);
 
于 2012-01-11T04:25:04.870 回答