-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.php
More file actions
32 lines (26 loc) · 820 Bytes
/
mysql.php
File metadata and controls
32 lines (26 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
$servername = "localhost"; // Replace with your MySQL server name
$username = "root"; // Replace with your MySQL username
$password = "admin@123"; // Replace with your MySQL password
$database = "imdb"; // Replace with your MySQL database name
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Connection successful
echo "Connected successfully";
$sql = "SELECT * FROM movies LIMIT 20";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
// Access the retrieved data
echo "Name: " . $row["name"] . "<br>";
}
} else {
echo "No results found";
}
// Close the connection
$conn->close();
?>