• PHP的PDO操作实例


    try{
          
           $dbms='mysql';          //数据库类型 ,对于开发者来说,使用不同的数据库,只要改这个,不用记住那么多的函数
           $host='127.0.0.1';      //数据库主机名
           $dbName='books';      //使用的数据库
           $user='root';           //数据库连接用户名
           $pass='';              //对应的密码
           $dsn="$dbms:host=$host;dbname=$dbName";
           $pdo = new PDO($dsn, $user, $pass);  //初始化一个PDO对象,就是创建了数据库连接对象$pdo
           
           */
           //echo $_POST['bookname'];
           //插入出数据库语句,图片数据前要加上0x,用于表示16进制数
           //$query = "insert into book(name,createtime,price,author,publish) value('$bookname','$booktime','$bookprice','$bookauthor','$bookpublish')";
           //$query = "insert into images(pic) values('".$name."','".$type."',0x".$imgdata.")")  
           //$query = "insert into book(name,createtime,price,author,publish,pic) values(':name',':createtime',':price',':author',':publish',0x".$imgdata.")";
           //$query = "insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x".$imgdata.")";
           //$result=$pdo->prepare($query);   //准备查询语句
           //$result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x".$imgdata.")");   //准备查询语句
           //$result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,0x.?)"); 
           //$result=$pdo->prepare("insert into book(name,createtime,price,author,publish) values(?,?,?,?,?)");
           //echo $_POST['imagedata'];
           $result=$pdo->prepare("insert into book(name,createtime,price,author,publish,pic) values(?,?,?,?,?,?)");
           //echo $_POST['bookname'];
           /*
           
           $result->bindValue(1,$_POST['bookname']);
           $result->bindValue(2,$_POST['booktime']);
           $result->bindValue(3,$_POST['bookprice']);
           $result->bindValue(4,$_POST['bookauthor']);
           $result->bindValue(5,$_POST['bookpublish']);
           $result->bindValue(6,$_POST['imagedata']);
           */
          // echo "<h1>".time()."</h1>"
          // echo $_POST['imagedata'];
           
           
           
           /*
           $result->bindParam(':name', $_POST['bookname']);
           $result->bindParam(':createtime',$_POST['booktime']);
           $result->bindParam(':price', $_POST['bookprice']);
           $result->bindParam(':author',$_POST['bookauthor']);
           $result->bindParam(':publish',$_POST['bookpublish']);
           */  
      /*      
            
            if($result->execute() > 0)
            {
             echo "<br/> insert pic success ";
             echo "<center>insert success!<br><br><a href='display.php'>!!!!!!!!!!!!!!qq</a></center>";
            }
            else
            {
             echo "<center>insert failed 26".mysql_error()."</center>";
            }
          }
          catch(PDOException $e)
          {
           die("Error:".$e->getMessage()."<br/>");
          }

  • 相关阅读:
    tcp/ip基础
    Fiddler进行模拟Post提交json数据,总为null解决方式(转)
    mysql function动态执行不同sql语句
    SQL语句中各个部分的执行顺序(转)
    shell的初步介绍
    linux分区
    转00600异常解决方案:ORA-00600: 内部错误代码, 参数: [19004], [], [], [], [], []
    一小时执行一次存储过程
    Oracle中的job的定时任务
    Oracle 存储过程错误之PLS-00201: 必须声明标识符
  • 原文地址:https://www.cnblogs.com/flintlovesam/p/4461552.html
Copyright © 2020-2023  润新知