Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

Take the PHP and MySQL Knowledge Assessment Quiz

Challenge your database development skills today

Difficulty: Moderate
Questions: 20
Learning OutcomesStudy Material
Colorful paper art representing a PHP and MySQL knowledge assessment quiz

Welcome to the PHP and MySQL Knowledge Assessment Quiz - a hands-on, multiple-choice challenge designed to evaluate your database scripting expertise. Ideal for developers, students, and IT professionals, this quiz covers real-world scenarios and reveals essential integration concepts. After completing it, participants will identify strengths, uncover improvement areas, and gain actionable insights for robust applications. You can customize any question in our editor for tailored practice. For more focused tests, try the PHP Fundamentals Knowledge Test or explore the IT Knowledge Assessment Quiz and browse all quizzes.

Which is the correct way to start a PHP code block?
/
<
PHP code blocks should begin with
What is the correct MySQL statement to retrieve all columns from a table named `users`?
GET ALL FROM users;
SHOW * FROM users;
SELECT * FROM users;
FETCH * users;
The SELECT * FROM users; statement is the standard SQL syntax to retrieve every column from the users table. Other options are not valid SQL commands. Using the * wildcard returns all fields.
Which PHP function checks if a variable is set and not null?
empty()
var_exists()
is_null()
isset()
isset() returns true if a variable exists and is not null. is_null() checks specifically for null values but would not verify existence. empty() checks for empty values but also considers zero and false as empty.
In MySQL, which key enforces that each record in a table is unique?
CHECK CONSTRAINT
PRIMARY KEY
FOREIGN KEY
UNIQUE INDEX
A PRIMARY KEY uniquely identifies each row in a table and enforces uniqueness. FOREIGN KEY maintains referential integrity but does not by itself guarantee uniqueness. CHECK CONSTRAINT enforces custom rules, not uniqueness.
Which PHP function is used to open a connection to MySQL using the mysqli extension?
mysqli_open()
new mysqli_connect()
mysqli_connect()
mysql_connect()
The mysqli_connect() function is the procedural way to establish a MySQL connection using the mysqli extension. mysql_connect() is deprecated and mysqli_open() does not exist. The correct call is mysqli_connect().
Identify the syntax error in the following PHP code: foreach($items as $item { echo $item; }
Incorrect variable naming convention
Missing semicolon after echo statement
Missing curly brace at the end of loop
Missing closing parenthesis in the foreach statement
The foreach statement is missing a closing parenthesis after $item before the opening curly brace. The echo statement has its semicolon. Fixing the parenthesis corrects the syntax.
Which SQL query updates the salary column by 10% for all employees older than 30 in a table called `employees`?
UPDATE employees SET salary = salary * 1.10 WHERE age > 30;
MODIFY employees INCREMENT salary BY 10% WHERE age > 30;
UPDATE employees SET salary = salary + 10 WHERE age > 30;
ALTER TABLE employees UPDATE salary FOR age > 30;
To increase salary by 10%, you multiply it by 1.10 in the UPDATE statement. The other syntaxes are invalid or would not apply the correct calculation.
In PDO, which method starts a database transaction?
begin()
openTransaction()
beginTransaction()
startTransaction()
The PDO::beginTransaction() method initiates a transaction. There is no startTransaction() or openTransaction(), and begin() is not a valid PDO method.
What function should you use to escape special characters in a string before including it in a SQL statement when using mysqli?
mysqli_real_escape_string()
mysqli_safe_string()
mysqli_secure()
mysqli_escape_html()
mysqli_real_escape_string() properly escapes special characters for use in SQL queries. The other functions do not exist or are not designed for SQL escaping. Prepared statements are recommended for stronger security.
Which MySQL index type is most suitable for accelerating full-text search on large text columns?
FULLTEXT
SPATIAL
HASH
BTREE
FULLTEXT indexes are specifically designed to optimize full-text searches on large text columns. BTREE is for general lookups and range queries. HASH and SPATIAL serve different use cases.
What does the following SQL query return? SELECT department, COUNT(*) FROM employees GROUP BY department;
Lists employees with department counts
Lists departments with employee counts
Returns total employees
Lists departments alphabetically
The query groups rows by department and returns each department alongside the count of its employees. It does not sort alphabetically unless ORDER BY is added. It reports counts per group.
Which MySQL clause filters records after grouping them?
FILTER
WHERE
HAVING
GROUP
HAVING is used to filter results after GROUP BY aggregation. WHERE filters rows before grouping. FILTER is not a standard MySQL clause for this purpose.
Which PHP function converts special characters to HTML entities to help prevent XSS attacks?
htmlspecialchars()
strip_tags()
html_entity_decode()
sanitize()
htmlspecialchars() converts special characters like < and > to HTML entities, preventing execution of malicious code in a browser. strip_tags() removes HTML tags but can strip content. html_entity_decode() decodes entities back to characters.
Which SQL statement retrieves records from two tables `orders` and `customers` based on matching customer_id?
SELECT * FROM orders LEFT JOIN customers ON orders.customer_id = customers.id;
SELECT * FROM orders INNER JOIN customers ON orders.customer_id = customers.id;
SELECT * FROM orders, customers ON orders.customer_id = customers.id;
SELECT * FROM orders JOIN customers WHERE orders.customer_id = customers.id;
An INNER JOIN with an ON clause returns rows where the customer_id matches. The second syntax is missing ON. The comma syntax is incorrect here, and LEFT JOIN would include non-matching rows.
Which technique helps optimize a slow MySQL query by showing how the database executes it?
DESCRIBE
ANALYZE
EXPLAIN
PROFILE
EXPLAIN provides details on how MySQL plans to execute a query, including index usage and join order. DESCRIBE shows table structure. ANALYZE and PROFILE are not standard commands for query plans.
In PDO, which attribute must be set to have errors thrown as exceptions?
PDO::ATTR_PERSISTENT
PDO::ATTR_ERRMODE with PDO::ERRMODE_EXCEPTION
PDO::ATTR_AUTOCOMMIT
PDO::ATTR_DEFAULT_FETCH_MODE
Setting PDO::ATTR_ERRMODE to PDO::ERRMODE_EXCEPTION instructs PDO to throw exceptions on errors. Other attributes control fetch modes, persistence, or autocommit behavior but do not trigger exceptions.
To model a many-to-many relationship between `students` and `courses`, which database design is optimal?
Add course_id column to students table
Create a join table student_courses with student_id and course_id
Use JSON column to hold courses per student
Store arrays of course IDs in a column in students
A separate join table (student_courses) with foreign keys to both students and courses is the normalized way to represent many-to-many relationships. Embedding arrays or JSON breaks normalization and hinders queries.
Which normal form ensures that no non-key attribute is transitively dependent on the primary key?
Third Normal Form (3NF)
Second Normal Form (2NF)
First Normal Form (1NF)
Boyce-Codd Normal Form (BCNF)
Third Normal Form (3NF) requires that all non-key attributes depend only on the primary key and not on other non-key attributes (no transitive dependencies). 2NF addresses partial dependencies but not transitive ones.
For bulk loading data from a CSV file into MySQL for large datasets, which command is most efficient?
REPLACE INTO ...
LOAD DATA INFILE
UPDATE ... SET ...
INSERT INTO ... VALUES() in a loop
LOAD DATA INFILE reads rows from a file directly into a table with minimal parsing overhead, making it far faster than issuing many INSERT statements. INSERT loops are slower and UPDATE is not appropriate for loading new data.
Which caching mechanism can be integrated with PHP to reduce database load for frequently accessed data?
Session caching
File_put_contents() cache
Memcached
fopen() cache
Memcached is an in-memory key-value store that PHP can use to cache query results or computed data, significantly reducing database hits. Sessions and file operations are not designed for scalable high-performance caching.
0
{"name":"Which is the correct way to start a PHP code block?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Which is the correct way to start a PHP code block?, What is the correct MySQL statement to retrieve all columns from a table named `users`?, Which PHP function checks if a variable is set and not null?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Learning Outcomes

  1. Analyse PHP code to identify syntax errors and best practices.
  2. Demonstrate proficiency in writing MySQL queries for data retrieval and manipulation.
  3. Apply secure coding principles in PHP-MySQL interactions.
  4. Identify optimal database schema designs for PHP applications.
  5. Evaluate performance considerations in PHP and MySQL integration.

Cheat Sheet

  1. Master PHP Syntax and Best Practices - Stick to standard PHP tags and avoid deprecated syntax. Clean code makes collaboration and debugging a breeze. Read more
  2. en.wikipedia.org
  3. Utilize Prepared Statements in MySQL - Use prepared statements to keep SQL injections at bay. Separation of code and data means safer queries. Read more
  4. geeksforgeeks.org
  5. Implement Proper Error Handling - Wrap risky code in try-catch blocks to handle errors gracefully. This keeps your app stable under unexpected conditions. Read more
  6. geeksforgeeks.org
  7. Secure Password Storage - Hash passwords with bcrypt instead of storing plain text. It's a powerful way to protect user credentials. Read more
  8. geeksforgeeks.org
  9. Validate and Sanitize User Input - Validate and sanitize inputs to prevent XSS or SQL attacks. Built-in filters ensure only safe data enters your app. Read more
  10. geeksforgeeks.org
  11. Design Optimal Database Schemas - Normalize tables and define clear relationships to avoid redundancy. A well-thought schema boosts performance and scalability. Read more
  12. databasejournal.com
  13. Understand MySQL Data Manipulation Statements - Master INSERT, SELECT, UPDATE, and DELETE for efficient data control. These statements form the backbone of data manipulation. Read more
  14. databasejournal.com
  15. Implement Defensive Coding Techniques - Escape outputs and avoid magic numbers with named constants. Defensive coding habits keep bugs and attacks away. Read more
  16. toxigon.com
  17. Optimize PHP and MySQL Performance - Optimize queries with proper indexing and caching strategies. Profiling tools help you spot and fix bottlenecks. Read more
  18. rtcamp.com
  19. Separate PHP Logic from HTML - Separate PHP logic from HTML using templates or MVC patterns. Clean separation makes maintenance and scaling effortless. Read more
  20. geeksforgeeks.org
Powered by: Quiz Maker