0

Insert data in database

How to insert data in mysql database using xammp and how to display with PHP

26th Apr 2018, 5:31 PM
Mohammad Ismail
Mohammad Ismail - avatar
4 Antworten
+ 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 }
26th Apr 2018, 5:48 PM
Toni Isotalo
Toni Isotalo - avatar
0
thanks bros
26th Apr 2018, 5:58 PM
Jamilu usman
Jamilu usman - avatar
0
This code is not working
3rd May 2018, 9:40 AM
Shubham Gupta
Shubham Gupta - avatar
14th Oct 2020, 11:25 AM
Caleb Whyte
Caleb Whyte - avatar