后端如何使用php,如何使用PHP作为离子框架的后端?

小编典典

当然 !

我和我的合伙人刚刚完成了将PHP作为后端集成的IONIC应用程序的工作。

就像常规的前端后端一样,请求和响应都是JSON形式。

为了快速入门,以下是我们为自己构建的示例代码:

send.php

// Prevent caching.

//header('Cache-Control: no-cache, must-revalidate');

// The JSON standard MIME header.

//header('Content-type: application/json');

$data = array(

"username" => "one",

"email" => "ifyoucanreadthis@yes.com",

"age" => 22

);

// Send the data.

echo json_encode($data);

?>

recieve.php

/*

* Collect all Details from Angular HTTP Request.

*/

$postdata = file_get_contents("php://input");

$request = json_decode($postdata);

$usr = $request->email;

$pass = $request->pass;

echo "

Username is : " . $usr . "
and password is : ". $pass."

"; //this will go back under "data" of angular call.

/*

* You can use $email and $pass for further work. Such as Database calls.

*/

?>

希望这对您有所帮助!

编辑1:

使用PDO的好处被高估了。在此处了解更多信息:http : //code.tutsplus.com/tutorials/pdo-

vs-mysqli-which-should-you-use–

net-24059

$servername = "localhost";

$username = "username";

$password = "password";

// Create connection

$conn = new mysqli($servername, $username, $password);

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

}

echo "Connected successfully";

?>

就角度编码而言,您可能会发现以下链接很有用(对不起,我的机器上没有角度编码):

2020-07-04

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值