note 127640 added to mysql-xdevapi-table.select
| From: | php dot user1577 at gmail dot com | Date: | Thu, 15 Sep 2022 21:50:37 +0000 |
| Subject: | note 127640 added to mysql-xdevapi-table.select | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219584@lists.php.net to get a copy of this message | ||
// Some simple script snippets for processing single database row
// ---------- Page - singleRow.php ----------
<?php
session_start();
require "./DatabaseClass.php";
?>
// ... other HTML Code
<head>
<link href="./bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<?php
$userId = '';
$userData = DatabaseClass::getUsersById($userId);
if (empty($userData)) {
echo "<tr><td colspan='3'> <p class='alert
alert-danger align-content-center'>No data found</p></td></tr>";
}
?>
<table class="table">
<thead>
<tr>
<td><strong>Name</strong></td>
<?php
echo "<td>" . $userData["name"] . "</td>";
?>
</tr>
<tr>
<td><strong>E-Mail</strong></td>
<?php
echo "<td>" . $userData["email"] .
"</td>";
?>
</tr>
<tr>
<td><strong>Password</strong></td>
<?php
echo "<td>" . $userData["password"] .
"</td>";
?>
</tr>
<tr>
<td><strong></strong></td>
<td></td>
</tr>
</thead>
</table>
</div>
</body>
// ---------- DatabaseClass.php ----------
<?php
class DatabaseClass {
private $userId = '';
public static function connect() {
$dbName = 'MyDatabase';
$dbHost = 'localhost';
$dbUsername = 'root';
$dbUserPassword = '';
try {
$conn = new PDO("mysql:host=$dbHost;dbname=$dbName;", $dbUsername,
$dbUserPassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
return $conn;
}
public static function getUsersById($userId) {
$db = DatabaseClass::connect();
$sql="SELECT * FROM Users WHERE Id = ?";
$stmt = $db->prepare($sql);
$stmt->execute([$userId]);
$data = $stmt->fetch(PDO::FETCH_ASSOC);
$db = null;
return $data;
}
}
?>
----
Server IP: 45.112.84.4
Probable Submitter: 185.85.3.173 (proxied: 185.17.14.59)
----
Manual Page -- https://php.net/manual/en/mysql-xdevapi-table.select.php
Edit -- https://main.php.net/note/edit/127640
Del: integrated -- https://main.php.net/note/delete/127640/integrated
Del: useless -- https://main.php.net/note/delete/127640/useless
Del: bad code -- https://main.php.net/note/delete/127640/bad+code
Del: spam -- https://main.php.net/note/delete/127640/spam
Del: non-english -- https://main.php.net/note/delete/127640/non-english
Del: in docs -- https://main.php.net/note/delete/127640/in+docs
Del: other reasons-- https://main.php.net/note/delete/127640
Reject -- https://main.php.net/note/reject/127640
Search -- https://main.php.net/manage/user-notes.php