首页 > 代码库 > php的链接数据库方式和返回json数据

php的链接数据库方式和返回json数据

header("Content-type:text/html;charset=utf-8");
    $servername = "localhost";//服务器地址
    $username = "root";//帐号
    $password = "Xiaowu34!@#";//密码
    $dbname = "job_qybk";//表名
    $conn=mysqli_connect($servername, $username, $password,$dbname);//连接数据库
        if(!$conn)
            die("数据库链接错误!");

    $sql = "select * from resume_information";//查选语句
    $result=mysqli_query($conn, $sql);

    if (mysqli_num_rows($result) > 0) {
         $ar=array();
    // 输出数据
    while($row = mysqli_fetch_assoc($result)) {
        //添加数组
         $ar[]=array(
             "Id" => $row["Id"],//编号
              "Sex"=>$row["Sex"]?"男":"女",//性别  1代表男 0代表女
             "Name" =>  $row["Name"],//姓名
             "Date" =>  $row["Date"],//出身年月
             "Place" =>  $row["Place"],//籍贯
             "Phone" =>  $row["Phone"],//手机号
             "Emergency" => $row["Emergency"],//紧急联系人
             "Mail"=>$row["Mail"],//邮箱
             "Present" =>  $row["Present"],//现居地
             "School" =>  $row["School"],//毕业院校
             "Education" =>  $row["Education"],//最高学历
             "Major" =>  $row["Major"],//专业
             "Certufucate"=>$row["Certufucate"],//专业证书
             "Grade" =>  $row["Grade"],//英语等级
             "Life" =>  $row["Life"],//工作经验
             "Resume" =>  $row["Resume"],//工作履历
             "Post" =>  $row["Post"],//应聘岗位
             "Position" =>  $row["Position"],//到岗时间
             "Photoshop"=>$row["Photoshop"]?"√":" ",// 1代表熟练 0代表不会
             "InDesign" =>  $row["InDesign"]?"√":" ",// 1代表熟练 0代表不会
             "IIIustrator" =>  $row["IIIustrator"]?"√":" ",// 1代表熟练 0代表不会
             "Premiere" =>  $row["Premiere"]?"√":" ",// 1代表熟练 0代表不会
             "Dreamweaver" =>  $row["Dreamweaver"]?"√":" ",// 1代表熟练 0代表不会
             "Flash" =>  $row["Flash"]?"√":" ",// 1代表熟练 0代表不会
             "Other" =>  $row["Other"],//其他
             "Fraction" =>  $row["Fraction"]//分数
         );
    }
    //返回json格式
         echo json_encode($ar) ;
    } else {
        echo "0";
    }
    ?>

  

php的链接数据库方式和返回json数据