Here is my code:
<?php
/*** mysql hostname ***/
$hostname = 'localhost';
/*** mysql username ***/
$username = 'root';
/*** mysql password ***/
$password = '';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=sample", $username, $password);
/*** echo a message saying we have connected ***/
echo 'Connected to database <br />';
$sql = "SELECT * FROM sampletable";
$stmt = $dbh->query($sql);
$result = $stmt->fetch(PDO::FETCH_ASSOC);
foreach($result as $key =>$val){
echo $key. '-' .$val.'<br />';
}
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
Now i am learning php, I want know about pdo connection to insert,update fetch data from database. I referred this link http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html#7.1
Now i got first column value.. May i know how to fetch all the records from database?
Thanks in advance.