0
How to connect the database and fetch the data from database in php??
3 ответов
+ 2
To connect to MySQL database server, you need to create a new connectionobject with the data source name, user name and password. The connectionobject is an instance of the PDO class. If something went wrong while establishing a connection to theMySQL server, an error message will display.
link:
php.net/manual/en/pdo.connections.php
To fetch data (and display) from database you can try this piece of code:
<?php
try {
//dbconnection
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
foreach($dbh->query('SELECT * from `Tablename` ') as $row) {
//print the result of an array expected on the screen
print_r($row);
}
$dbh = null;
//this improve to handle errors and to help to resolving them
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
ALSO REMEMBER THAT:
- You can't submit forms on SoloLearn.
- There is a limit to what you can do on SoloLearn.
So...try XAMPP or other application and run php script on your pc.
+ 2
you're welcome
+ 1
Thabk you BOSS.