zoukankan      html  css  js  c++  java
  • POD

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?php
    
    //定义数据源
    $dsn = "mysql:dbname=mydb;host=localhost";
    //$dsn = "sqlsrv:dbname=mydb;host=localhost";
    
    //造pdo对象
    $pdo = new PDO($dsn,"root","123");
    
    //写SQL语句
    $sql = "select * from Info";
    
    //准备执行SQL语句
    $st = $pdo->prepare($sql);
    
    //执行预处理语句
    if($st->execute())
    {
        /*while($attr = $st->fetch())
        {
            print_r($attr);
            echo "<br>";
        }*/
        
        //从结果集中取所有数据,返回二维数组
        //print_r($st->fetchAll(PDO::FETCH_NUM));
        
        //从结果集中取一条数据中的某一列,返回字符串
        //var_dump($st->fetchColumn(1));
        
        //从结果集中取一条数据,返回一个实体类的对象
        //var_dump($st->fetchObject());
        
        
        
        
    }
    else
    {
        echo "执行失败!";
    }
    
    
    
    
    ?>
    
    </body>
    </html>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?php
    
        //造PDO对象
        $pdo = new PDO("mysql:dbname=mydb;host=localhost","root","123");
        
        //写SQL语句
        $sql = "insert into Info values(?,?,?,?,?)";
        
        //准备SQL语句
        $st = $pdo->prepare($sql);
        
    /*    //给SQL语句分配变量
        $st->bindParam(1,$code);
        $st->bindParam(2,$name);
        $st->bindParam(3,$sex);
        $st->bindParam(4,$nation);
        $st->bindParam(5,$birthday);
        
        //给变量赋值
        $code = "p120";
        $name = "接口";
        $sex = true;
        $nation = "n002";
        $birthday = "1988-2-3";
        
        //执行SQL语句
        $st->execute();
        
        */
        
        //执行SQL语句,简便方法
        $st->execute(array('p030','克隆',true,'n001','1989-2-3'));
        
        
        
        
        
    ?>
    </body>
    </html>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <body>
    <?php
    
        //造PDO对象
        $pdo = new PDO("mysql:dbname=mydb;host=localhost","root","123");
        
        //写SQL语句
        $sql = "insert into Info values(:code,:name,:sex,:nation,:birthday)";
        
        //准备SQL语句
        $st = $pdo->prepare($sql);
        
        /*//绑定参数
        $st->bindParam("c",$code,PDO::PARAM_STR);
        $st->bindParam("n",$name,PDO::PARAM_STR);
        $st->bindParam("s",$sex,PDO::PARAM_STR);
        $st->bindParam("na",$nation,PDO::PARAM_STR);
        $st->bindParam("b",$birthday,PDO::PARAM_STR);
        
        //参数赋值
        $code = "p180";
        $name = "会啊";
        $sex = true;
        $nation = "n002";
        $birthday = "1988-2-3";
        
        //执行
        $st->execute();*/
        
        
        
        $st->execute($_POST);
        
        
        
    
    ?>
    </body>
    </html>
  • 相关阅读:
    Apache ECharts
    navicate10破解版 in win
    mysql5.7.23免安装配置说明in win7
    ubuntu安装intellij IDEA ultimate破解
    java1015 leetcode1 twosum approach2 Map-doc generic PESC type argument/(? extends | super %bounded) parameterized type
    笔试题学习(dp,重叠子问题,卡特兰数,手电过桥,最长公共子序列)
    selfish mining:block‐withholding attacks
    矿工找到block的概率分布函数和函数图像
    proof of reserves and proof of liabilities and fractional reserve
    soft fork and hard fork
  • 原文地址:https://www.cnblogs.com/zhanghaozhe8462/p/5361307.html
Copyright © 2011-2022 走看看