Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
maybe this will work?
- Loading branch information
Showing
1 changed file
with
32 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
<html> | ||
|
||
<table> | ||
|
||
<tr> | ||
|
||
<td>Name</td> | ||
<td>Age</td> | ||
</tr> | ||
<?php | ||
$servername = "localhost"; | ||
$username = "username"; | ||
$password = "password"; | ||
$dbname = "myDB"; | ||
|
||
// Create connection | ||
$conn = mysqli_connect($servername, $username, $password, $dbname); | ||
// Check connection | ||
if (!$conn) { | ||
die("Connection failed: " . mysqli_connect_error()); | ||
} | ||
|
||
// sql to create table | ||
$sql = "CREATE TABLE MyGuests ( | ||
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, | ||
firstname VARCHAR(30) NOT NULL, | ||
lastname VARCHAR(30) NOT NULL, | ||
email VARCHAR(50), | ||
reg_date TIMESTAMP | ||
)"; | ||
|
||
if (mysqli_query($conn, $sql)) { | ||
echo "Table MyGuests created successfully"; | ||
} else { | ||
echo "Error creating table: " . mysqli_error($conn); | ||
} | ||
|
||
mysqli_close($conn); | ||
?> | ||
|
||
// Enter username and password | ||
$username = root; | ||
$password = root; | ||
|
||
// Create database connection using PHP Data Object (PDO) | ||
$db = new PDO("mysql:host=localhost;dbname=test", $username, $password); | ||
|
||
// Identify name of table within database | ||
$table = 'age'; | ||
|
||
// Create the query - here we grab everything from the table | ||
$stmt = $db->query('SELECT * from '.$table); | ||
|
||
// Close connection to database | ||
$db = NULL; | ||
|
||
while($rows = $stmt->fetch()){ | ||
echo "<tr><td>". $rows['Name'] . "</td><td>" . $rows['Age'] . "</td></tr>"; | ||
}; | ||
?> | ||
</table> | ||
</html> |