Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $hostname ='localhost:3306';
- $username = 'root';
- $password = '';
- try
- {
- $dbh = new PDO("mysql:host=$hostname;dbname=test",$username,$password);
- echo 'Connected to database <br/>';
- $dbh->setattribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $ID = 1;
- $stmt =$dbh->prepare("select * from cities where id=:ID");
- $stmt->bindParam(':ID',$ID, PDO::PARAM_INT);
- $stmt->execute();
- $result =$stmt->fetchAll();
- foreach($result as $row)
- {
- echo $row['id'].'<br/>';
- echo $row['population'].'<br/>';
- echo $row['country_code'].'<br/>';
- }
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement