about 9 years ago
Access data from mysql using PDO includes the following steps:
connect to a MySQL database:
$db_conn = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password);
create a select statement and then execute it by using query() method.
$sql = 'SELECT * from tablename';
$exec = $db_conn->query($sql);
set the fetch mode(PDO::FETCH_ASSOC) by using setFetchMode() method
$q->setFetchMode(PDO::FETCH_ASSOC);
fetch each row by using fetch method of PDOstatement
Example:
$username="username"; //set username of database $password="password"; //set password of database $dbname="dbname"; //set database name $host="hostname"; //set hostname //connecting using PDO $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password); $sql = 'SELECT * from table1'; $q = $conn->query($sql); //fetching data $q->setFetchMode(PDO::FETCH_ASSOC); while ($r = $q->fetch()){ print_r($result); }
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)