Tuesday, November 29, 2022

PDO select query with case statement

PDO select query with case statement


Hello to all, welcome to In this post, I am showing PDO select query with case statement. First time I am showing mysql pdo case statements.


Here is the working code for PDO select query with case statement:

$servername = “localhost”;
$username = “root”;
$password = “root”;

try {
$conn = new PDO(“mysql:host=$servername;dbname=user”, $username, $password);
// set the PDO error mode to exception
echo “Connected successfully”;
catch(PDOException $e)
echo “Connection failed: ” . $e->getMessage();
$upcoming_appointment = $conn->prepare(“SELECT user.*,
WHEN user.field = ‘jquery’ THEN ‘love’
ELSE ‘okay’
END AS ‘field_status’
FROM `user`”);
$upcomingappointments= $upcoming_appointment->fetchAll(\PDO::FETCH_OBJ);
echo ‘<div class=”container”><table class=”table table-dark”>
<th scope=”col”>#</th>
<th scope=”col”>Name</th>
<th scope=”col”>Field</th>
<th scope=”col”>Intrest</th>
foreach ($upcomingappointments as $BOOKING) {
echo “<tr>”;
echo “<td>”.$BOOKING->id.”</td>”;
echo “<td>”.$BOOKING->name.”</td>”;
echo “<td>”.$BOOKING->field.”</td>”;
echo “<td>”.$BOOKING->field_status.”</td>”;
echo “</tr>”;
echo ‘</tbody>

There are so many queries in pdo for mysql data and I will let you know all. Please do comment if you any query related to this post. Thank you.

the authortherichpost
Hello to all. Welcome to Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 8, Angular 9, Angular 10, Angular 11, Angular12, Angular 13, Angular 14, Angular 15, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.