我怎样才能使一个简单的api,可以连接到mysql


How can I make a simple api that can connect to mysql?

我需要帮助如何使PHP的API。我试图使一个web服务器通过PHP与另一个web服务器通信。

我也希望它更新MySQL代码。我用的是$_GET,但它不太安全。这是我的代码,你能看一下吗?

<?php
/*
example: website-url-here.com/?command=insert-command-here&password=testing
*/
$command = $_GET["command"];
$password = $_GET["password"];
if ($password == "testing") {
//Was not a good idea, less secure.      
//echo eval($command);
//More secure
  if ($command == "create-user")
  {
   //create user command here
  } 
  else if ($command == "delete-user")
  {
   //delete user command here
  } 
  else
  {
  die("Command is incorrect");
  }
}
echo "Success";
?>

这个问题太开放了,无法在StackOverflow中回答。试着读一点关于REST的书,多读一些关于PDO的书,尤其是在清理用户输入的上下文中。

想想如果有人用[url]?command=rm -rf .&password=testing来调用你的api会发生什么