Advertisement
Riju18

no.76_pdo[insert values with bindvalues]

Dec 18th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1.  
  2. <!DOCTYPE html>
  3. <html>
  4.   <head>
  5.     <meta charset="utf-8">
  6.     <title>class & method exist</title>
  7.     <link rel="stylesheet" href="/css/master.css">
  8.     <style media="screen">
  9.       *{margin: 0;padding: 0;}
  10.        body{background-color: gray;}
  11.       .header
  12.       {
  13.         width: 960px;
  14.         height: 50px;
  15.         background: green;
  16.         margin: 20px auto;
  17.         border: 2px solid white;
  18.         border-radius: 10px;
  19.       }
  20.       .header h2
  21.       {
  22.         color: white;
  23.         margin-left: 200px;
  24.         padding: 8px;
  25.         font-family: arial;
  26.       }
  27.       .main
  28.       {
  29.         width: 960px;
  30.         background: green;
  31.         margin: 10px auto;
  32.         border: 1px solid white;
  33.         border-radius: 20px;
  34.         overflow: hidden;
  35.       }
  36.       .main .code
  37.       {
  38.         margin: 10px 20px;
  39.         color: white;
  40.         font-weight: bold;
  41.         font-size: 20px;
  42.         font-family: verdana;
  43.         overflow: hidden;
  44.       }
  45.       .footer
  46.       {
  47.         width: 960px;
  48.         height: 50px;
  49.         background: green;
  50.         margin: 10px auto;
  51.         border: 2px solid white;
  52.         border-radius: 10px;
  53.       }
  54.       .footer h2
  55.       {
  56.         color: white;
  57.         margin-left: 250px;
  58.         padding: 8px;
  59.         font-family: arial;
  60.       }
  61.     </style>
  62.   </head>
  63.   <body>
  64.     <div class="header">
  65.       <h2>work with PDO:</h2>
  66.     </div>
  67.     <div class="main">
  68.       <div class="code">
  69.         <p>pdo_insert values:(with bind values)</p>
  70.         <br>
  71.         <?php
  72.           $dsn = "mysql:dbname=test;host=localhost";
  73.           $user = "root";
  74.           $password = "";
  75.           try {
  76.             $db = new PDO( $dsn, $user, $password );   //pdo is used to connect any database engine;
  77.             echo "database is updated successfully";
  78.           } catch (PDOException $e) {
  79.             echo "somthing error with database....".$e->getMessage();
  80.           }
  81.           $name = "s";
  82.           $skill = "c,c++,python";
  83.           $insert = "insert into info(name,skill) values( :name, :skill )";
  84.           $prepare = $db->prepare($insert);
  85.           $prepare->bindvalue( ':name', "x" );         //bindvalue can pass both variable & value;
  86.           $prepare->bindvalue( ':skill', "c#,python");
  87.           $prepare->execute();
  88.          ?>
  89.       </div>
  90.     </div>
  91.     <div class="footer">
  92.       <h2>&copy; the hompage is created by <i>Riju</i></h2>
  93.     </div>
  94.   </body>
  95. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement