localDatabase.php
2018-02-10 本文已影响0人
曾柏超
<?php
$conn = mysqli_connect(
'localhost', /* The host to connect to 连接MySQL地址 */
'root', /* The user to connect as 连接MySQL用户名 */
'root', /* The password to use 连接MySQL密码 */
'mydatabase'); /* The default database to query 连接数据库名称*/
if (!$conn) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
$name = $_GET["name"];
$sql="insert into student values('$name','男','itcast0005',23);";
//$sql="insert into student values('zackkkkkkk','男','itcast0005',23);";
$result = mysqli_query($conn,$sql);
//echo $result;
if ($result){
$arry = array( 'messsage' => "success");
echo json_encode($arry);
}else{
$arry = array( 'messsage' => "failure");
echo json_encode($arry);
echo $name;
}
//查找
$sql = "select * from student";
$rs = mysqli_query($conn,$sql);
$r= mysqli_fetch_all($rs);
var_dump($r);
?>