Here is the link to the SQL syntax for the
SELECT command in MariaDB. That is the database software your error code says you are using.
SELECT
[ALL | DISTINCT | DISTINCTROW]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
[SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
select_expr [, select_expr ...]
[ FROM table_references
[WHERE where_condition]
[GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]]
[HAVING where_condition]
[ORDER BY {col_name | expr | position} [ASC | DESC], ...]
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
[PROCEDURE procedure_name(argument_list)]
[INTO OUTFILE 'file_name' [CHARACTER SET charset_name] [export_options]
INTO DUMPFILE 'file_name' INTO var_name [, var_name] ]
[[FOR UPDATE | LOCK IN SHARE MODE] [WAIT n | NOWAIT] ] ]
export_options:
[{FIELDS | COLUMNS}
[TERMINATED BY 'string']
[[OPTIONALLY] ENCLOSED BY 'char']
[ESCAPED BY 'char']
]
[LINES
[STARTING BY 'string']
[TERMINATED BY 'string']
]
By your own admission, you stated that you are not a programmer and that you starting to learn. No problem, in that case you should first check if your query works in a database client before you try to put it into PHP scripting. A database client usually has much more helpful ways to describe what is going wrong with your SQL query. on the MariaDB site, the use of
HeidiSQL is recommended.
Your query:
SELECT * FROM browsing_histories WHERE username = ?
Doesn't seem it is properly terminated.
And is the question mark allowed as parameter content?
Or is the query treated as if you are looking for one or more user names that have the name '?' ?
Anyway, a database client could already have told you that. More extensive database clients often come with an option to see how long a query takes on the database you are connected to, which tables/indexes are consulted for that query, etc. Might not be useful information for you right now, but if your thing picks up and needs to scale, you will be very glad you have access to such tools.
Another tip: looking for optimizations to make your code faster? If there is any access to any type of database involved, check first how you can optimize your queries first. That is more often than not where you can gain a lot more. Fast code or slow code, both wait just as long for your database query to produce results...
Sql Syntax ErrorWithout access to your database, I just started up my
XAMPP environment (which is useful for PHP script development on Windows) to connect to a MySQL database (
PHPmyadmin) and show you how the query should be.
I cannot state enough the importance of using a database client first for checking database queries that need to be in code. Which in and of itself is already a sub-optimal practice (for applications that need to scale), but PHP, so who cares.