0
How can you use php to open the database (sql)?
3 Answers
+ 1
mysqli_connect($_host,$_username,$_password.$_dbName)
0
Or PDO:
<?php
$user = "";
$pass = "";
$conn = new PDO('mysql:host=localhost;dbname=myDB', $user, $pass);
?>
- 2
Make your question specific. Do you want to connect to the Database or Do you want to retrieve Results of a Query from the Database.
To connect to the Database use.
$conn=mysqli_connect("localhost", "root", "password", "my-database")
localhost= that is your server
root= your database username
password= your database password
my-database= your selected database
To retrieve result of a Query from the Database
$sql="SELECT * FROM table";
$result=$conn->query($sql);
* = this means select all columns
table= this is your selected table name
Hope you have understood