Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>class & method exist</title>
- <link rel="stylesheet" href="/css/master.css">
- <style media="screen">
- *{margin: 0;padding: 0;}
- body{background-color: gray;}
- .header
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 20px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .header h2
- {
- color: white;
- margin-left: 200px;
- padding: 8px;
- font-family: arial;
- }
- .main
- {
- width: 960px;
- background: green;
- margin: 10px auto;
- border: 1px solid white;
- border-radius: 20px;
- overflow: hidden;
- }
- .main .code
- {
- margin: 10px 20px;
- color: white;
- font-weight: bold;
- font-size: 20px;
- font-family: verdana;
- overflow: hidden;
- }
- .footer
- {
- width: 960px;
- height: 50px;
- background: green;
- margin: 10px auto;
- border: 2px solid white;
- border-radius: 10px;
- }
- .footer h2
- {
- color: white;
- margin-left: 250px;
- padding: 8px;
- font-family: arial;
- }
- </style>
- </head>
- <body>
- <div class="header">
- <h2>work with PDO:</h2>
- </div>
- <div class="main">
- <div class="code">
- <p>pdo_select values:</p>
- <br>
- <?php
- $dsn = "mysql:dbname=test;host=localhost";
- $user = "root";
- $password = "";
- try {
- $db = new PDO( $dsn, $user, $password ); //pdo is used to connect any database engine;
- } catch (PDOException $e) {
- echo "connection error".$e->getMessage();
- }
- $id=1;
- /*$select = "select * from info";
- $initQuery = $db->query($select);
- foreach ($initQuery as $value) {
- echo $value['name']."->".$value['skill']."<br>";
- }*/
- $select = "select * from info where id=?"; //for a particular id;
- $initQuery = $db->prepare($select);
- $initQuery->execute( [$id] );
- while ( $data = $initQuery->fetch() ) {
- echo "Name: ".$data['name']." , skill: ".$data['skill']."<br>";
- }
- /*or*/
- $select = "select * from info where id=:id"; //for a particular id;
- $initQuery = $db->prepare($select);
- $initQuery->execute( [':id'=$id] );
- while ( $data = $initQuery->fetch() ) {
- echo "Name: ".$data['name']." , skill: ".$data['skill']."<br>";
- }
- ?>
- </div>
- </div>
- <div class="footer">
- <h2>© the hompage is created by <i>Riju</i></h2>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement