Hi! Could we please enable some services and cookies to improve your experience and our website?

PHPize Online / SQLize Online  /  SQLtest Online

A A A
Login    Share code      Blog   FAQ

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

Copy Format Clear
CREATE TABLE employees ( employee_id SERIAL PRIMARY KEY, first_name CHARACTER VARYING (20), last_name CHARACTER VARYING (25) NOT NULL, email CHARACTER VARYING (100) NOT NULL, phone_number CHARACTER VARYING (20), hire_date DATE NOT NULL, job_id INTEGER NOT NULL, salary NUMERIC (8, 2) NOT NULL, manager_id INTEGER, department_id INTEGER ); INSERT INTO employees( employee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, manager_id, department_id ) VALUES ( 102, 'Lex', 'De Haan', 'lex.de haan@sqltutorial.org', '515.123.4569', '1993-01-13', 5, 17000.00, 100, 9 ),( 103, 'Alexander', 'Hunold', 'alexander.hunold@sqltutorial.org', '590.423.4567', '1990-01-03', 9, 9000.00, 102, 6 ),( 104, 'Bruce', 'Ernst', 'bruce.ernst@sqltutorial.org', '590.423.4568', '1991-05-21', 9, 6000.00, 103, 6 ),( 105, 'David', 'Austin', 'david.austin@sqltutorial.org', '590.423.4569', '1997-06-25', 9, 4800.00, 103, 6 ),( 106, 'Valli', 'Pataballa', 'valli.pataballa@sqltutorial.org', '590.423.4560', '1998-02-05', 9, 4800.00, 103, 6 ),( 107, 'Diana', 'Lorentz', 'diana.lorentz@sqltutorial.org', '590.423.5567', '1999-02-07', 9, 4200.00, 103, 6 ),( 108, 'Nancy', 'Greenberg', 'nancy.greenberg@sqltutorial.org', '515.124.4569', '1994-08-17', 7, 12000.00, 101, 10 ),( 109, 'Daniel', 'Faviet', 'daniel.faviet@sqltutorial.org', '515.124.4169', '1994-08-16', 6, 9000.00, 108, 10 ); CREATE TABLE favoriteworker (myid int, employee_id int); INSERT INTO favoriteworker VALUES (1, 103), (1, 105);;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear
Copy Format Clear
<?php $myid = 1; $query = ' SELECT * FROM employees JOIN favoriteworker ON favoriteworker.employee_id = employees.employee_id WHERE favoriteworker.myid = ?'; // get DB version using PDO $stmt = $pdo->prepare($query); $stmt->execute([$myid]); $favorites_employees = $stmt->fetchAll(PDO::FETCH_ASSOC); print_r($favorites_employees);
Copy Clear