0
Insert data in database
How to insert data in mysql database using xammp and how to display with PHP
4 Respuestas
+ 4
Start with your connection
$name = "name";
$host = "127.0.0.1";
$user = "root";
$pass = "";
$db = new PDO("mysql:host=$host;dbname=$name", "$user", "$pass");
Those are the default values. You should always use localhost to connect to your database.
mysql querys are made from your connection object
$query = $db->query("INSERT INTO users (name, pass) VALUES ('toni', '1234')");
Here's the same with prepared statement
$query = $db->prepare("INSERT INTO users (name, pass) VALUES (:name, :pass)");
$query->bindParam(":name", "toni");
$query->bindParam(":pass", "1234");
$query->execute();
On SELECT query after executing you need to fetch your data
while ($row = $query->fetch())
{
echo $row['name']; //Column name
}
0
thanks bros
0
This code is not working