zoukankan      html  css  js  c++  java
  • 四、php基础

    php里衔接变量和字符串用【.】

      echo $name."<br>";
      echo $name.$age;

    php连接数据库:
      1、建立链接
      2、数据操作
      3、结果处理

    mysql_connect(); php和mysql连接,apache解析

    1、在html表单中post、get传输数据;
       <form action="getregister.php" method="post"> //html代码
    2、建立php文件,如下:php语句可以写在<body>标签中
      <?php
      //a、创建与数据库连接
      $con=mysql_connect("localhost:13306","root","123456");
      if($con){
      echo "sucess<br>";
      }else{
      echo "fail".mysql_error();
      }


      //b、选择数据库和编码方式
      mysql_select_db("stu");
      mysql_query("set names utf8");


      //c、操作语句:这里是查询语句
      $query="select * from stu" ;
      $rest=mysql_query($query);
      echo "<table border='1'>";
      while($row=mysql_fetch_row($rest)){
       echo "<tr>";
      echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
      echo "</tr>";
      }
      echo "</table>";

    ?>


























    <?php
    /*$uname=$_GET['username'];
    $umobile=$_GET['tel'];
    $uid=$_GET['code'];*/

    /*$uname=$_POST['username'];
    $umobile=$_POST['tel'];
    $uid=$_POST['code'];*/



    //插入
    $con=mysql_connect("localhost:13306","root","123456");
    if($con){
    echo "sucess<br>";
    }else{
    echo "fail".mysql_error();//
    }
    mysql_select_db("stu");
    mysql_query("set names utf8");


    /*$sql="insert into stu values('$uid','$uname','$umobile')";
    $res=mysql_query($sql);
    if($res){
    echo "sucess01";
    }else{
    echo "fail01".mysql_error();
    }*/



    //查询语句
    $query="select * from stu" ;
    $rest=mysql_query($query);
    echo "<table border='1'>";
    while($row=mysql_fetch_row($rest)){
    echo "<tr>";
    echo "<td>$row[0]</td><td>$row[1]</td><td>$row[2]</td>";
    echo "</tr>";
    }
    echo "</table>";

    ?>


  • 相关阅读:
    判断一个点是否在一个不规则多边形内算法
    vue-cli 3.0 安装和创建项目流程
    微信小程序分享朋友圈的实现思路与解决办法
    vue2.0中关于active-class
    Nginx服务启动脚本
    Linux系统优化
    URL检测脚本
    Mysql读写分离php脚本
    Memcahed服务异常监控脚本
    一致性哈希算法PHP测试片段
  • 原文地址:https://www.cnblogs.com/ceshixuexi/p/7241895.html
Copyright © 2011-2022 走看看