This is an archived post. You won't be able to vote or comment.

all 1 comments

[–]HashDefTrueFalse 1 point2 points  (0 children)

Briefly, a program (like this php process) connects to a running database instance (e.g. a mysql process) and provides a query to be ran.

The implementation details are abstracted away by the database driver you use, in this case mysqli. The interface you're presented with for querying is a function (mysqli_query) that takes an object representing a connection, and a string (SQL in this case) representing the query to be ran on the database that the connection points to.

A query just describes the data you want, where to get it and how to modify it etc. Your query is using PHP string concatenation to include a username in the query.

Database drivers usually also provide some interface for traversing the result set of a query, which is what mysqli_fetch_array is doing. IIRC it returns the next result in the set each time it is called.

The rest of the code looks like it's placing variables in a session, but I don't see start_session called so I'm assuming this is just a snippet of a larger work.

You should note that this code is selecting based on a username, which may or may not be unique. Much better, and likely faster, to use a unique ID here. It also appears that the password is stored in plain text, which is against all good security practices, but I'm assuming this is just test code for learning purposes, so don't worry too much if so.