PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE customers ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), region VARCHAR(50) ); CREATE TABLE orders ( id INT AUTO_INCREMENT PRIMARY KEY, customer_id INT, order_date DATE, total_amount DECIMAL(10, 2), FOREIGN KEY (customer_id) REFERENCES customers(id) ); INSERT INTO customers (name, region) VALUES ('Bob', 'Skagen'), ('Alex', 'East'); INSERT INTO orders (customer_id, order_date, total_amount) VALUES (1, '2024-05-10', 100), (1, '2024-05-20', 150);
Copy Clear
Copy Format Clear
<?php use Carbon\Carbon; $now = Carbon::now()->format('d/m/Y'); printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion()); $query = "SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE IF( c.name = 'Bob', NOT EXISTS ( SELECT 1 FROM orders o2 WHERE o2.customer_id = c.id AND o2.id != o.id ), c.region = 'East' );"; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_OBJ); var_dump($row); if ($row > 0) { echo "Yeah!"; }
Show:  
Copy Clear