0
0
PHPprogramming~5 mins

Executing queries with query method in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the query method do in PHP's mysqli?
The query method sends an SQL query to the database and returns the result set or false if the query fails.
Click to reveal answer
beginner
How do you check if a query was successful in PHP?
You check if the result of $mysqli->query() is not false. If it is false, the query failed.
Click to reveal answer
beginner
What type of value does query return for a SELECT statement?
It returns a mysqli_result object which you can use to fetch rows from the result set.
Click to reveal answer
beginner
What does query return for an INSERT, UPDATE, or DELETE statement?
It returns true if the query was successful, or false if it failed.
Click to reveal answer
beginner
How do you fetch rows from the result of a query?
Use methods like fetch_assoc() on the mysqli_result object to get rows as associative arrays.
Click to reveal answer
What does $mysqli->query() return when a SELECT query is successful?
ATrue
BFalse
CA mysqli_result object
DAn integer
What does $mysqli->query() return when an INSERT query is successful?
AA mysqli_result object
BTrue
CFalse
DNull
How can you check if a query failed?
ACheck if <code>query</code> returns <code>false</code>
BCheck if <code>query</code> returns <code>true</code>
CCheck if <code>query</code> returns a string
DCheck if <code>query</code> returns an integer
Which method do you use to get rows from a mysqli_result object?
Aexecute()
Bquery()
Cconnect()
Dfetch_assoc()
What happens if you run query with a wrong SQL syntax?
AIt returns false
BIt returns true
CIt returns an empty result
DIt throws an exception automatically
Explain how to use the query method to run a SELECT statement and get results.
Think about sending the query, checking success, and reading rows.
You got /3 concepts.
    Describe what the query method returns for different types of SQL statements.
    Consider the difference between queries that return data and those that just change data.
    You got /3 concepts.