zoukankan      html  css  js  c++  java
  • new mysqli_ and 旧mysql

    旧的php处理语法:

    1.

    <select name="s" onChange="redirec()">
    <option selected>请选择</option>
    <?php
    $conn=mysql_connect("localhost","root",""); //连接MySQL服务器
    mysql_select_db("PXSCJ",$conn); //选择PXSCJ数据库
    mysql_query("SET NAMES gb2312"); //将字符集设为gb2312
    $sql="select distinct 专业 from XSB";    // sql 内容
    $result=mysql_query($sql);                 //定义接口
    while($row=mysql_fetch_array($result))           //定义循环
    {
    $ZY=$row['专业'];                                         //打印结果    
    echo "<option value='$ZY'>$ZY</option>";
    }
    ?>

    2.新的php 的处理语法

    sample 1.

    <?php
    ini_set('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    //print_r($_GET);
    //exit;
    $XH=$_GET['XH']; //取得XH的值
    $KCM=$_GET['KCM']; //取得KCM的值
    header('Content-Type:text/html;charset=uft8'); //发送header,将编码设为uft8
    //$db=new PDO("mysql:host=localhost;dbname=PXSCJ","root","");
    $conn= new mysqli('localhost','root','','PXSCJ');                              //连接MySQL服务器
    if (mysqli_connect_errno($conn))                                         
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    mysqli_set_charset($conn, "utf8");                                                     //将字符集设为uft8
    $sql="select 成绩 from CJB where 学号='$XH' and 课程号=(select 课程号 from KCB where 课程名='$KCM')";   // sql 内容
    if ($result=mysqli_query($conn,$sql))                                                //定义接口
    {
    // Fetch one and one row
    while ($row= $result->fetch_object())                                               //定义循环
    {
    printf($row->成绩);                                                                         //打印结果
    }
    // Free result set
    mysqli_free_result($result);
    }

    mysqli_close($conn);
    ?>

    sampe 2.

    <?php
    //1,连接
    $conn=mysqli_connect("localhost","root","root");
    if(mysqli_connect_errno($conn))
    die("无法链接到服务器");
    //2,选择数据库
    mysqli_select_db($conn,"xuexi51")or die("error");
    //3,SQL查询
    $sql="SELECT * FROM liuyanban";//多了个,

    $result=mysqli_query($conn,$sql);

    $data=mysqli_fetch_row($result);

    print_r($data); //print不能打印数组
    mysqli_close($conn);
    ?>

    sample 3:
    http://www.blogjava.net/nkjava/archive/2015/01/20/422291.html


    sampe 4:
    http://www.w3cschool.cn/php/func-mysqli-fetch-row.html

  • 相关阅读:
    SharePoint添加列表
    js求和
    经典.net面试题目
    sharepoint常见操作
    添加webpart时出现“此网页上的某个Web部件或Web表单控件无法显示或导入。该类型未注册为安全类型 。”
    关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
    RegisterStartupScript,RegisterClientScriptBlock,Response.Write 简单说明区别
    jquery中的ready函数与window.onload谁先执行
    TreeView的TreeNode点击展示展开和收缩的效果
    如何让 TreeView 的节点不要生成 超级 链接
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/6781811.html
Copyright © 2011-2022 走看看