Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+10 votes
1.3k views
in Q2A Core by

First time I start running Q2A site but i got belows error in nginx error log:

2022/07/06 18:01:20 [error] 18996#22728: *7 FastCGI sent in stderr: "PHP Fatal error:  Uncaught mysqli_sql_exception: Table 'q2a_db.qa_options' doesn't exist in H:\nginx_test\nginx\qa\qa-include\qa-db.php:227
Stack trace:
#0 H:\nginx_test\nginx\qa\qa-include\qa-db.php(227): mysqli->query()
#1 H:\nginx_test\nginx\qa\qa-include\qa-db.php(202): qa_db_query_execute()
#2 H:\nginx_test\nginx\qa\qa-include\qa-db.php(557): qa_db_query_raw()
#3 H:\nginx_test\nginx\qa\qa-include\qa-db.php(590): qa_db_single_select()
#4 H:\nginx_test\nginx\qa\qa-include\app\options.php(135): qa_db_multi_select()
#5 H:\nginx_test\nginx\qa\qa-include\qa-base.php(403): qa_preload_options()
#6 H:\nginx_test\nginx\qa\qa-include\qa-page.php(36): qa_initialize_postdb_plugins()
#7 H:\nginx_test\nginx\qa\qa-include\qa-index.php(188): require('...')
#8 H:\nginx_test\nginx\qa\index.php(27): require('...')
#9 {main}
  thrown in H:\nginx_test\nginx\qa\qa-include\qa-db.php on line 227" while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1:81"

Obviously, it has successfully connected to the database service, but has not accessed the specified table.
It looks the site not create required table in database at first running.

What I do:
Configure the site according to "https://docs.question2answer.org/install/".
Start php-cgi.exe, start nginx.exe, access index.php
=> Got state code 500, got error above in error.log

What should I do?

Software version:
Q2A: 1.8.6
PHP: 8.1.8
nginx: 1.23.0
MySQL: 8.0.25

OS: windows 10

Q2A version: 1.8.6
by
+1
1. Have you properly set the database configuration in qa-config.php file?
2. Does the user have the appropriate privileges? (e.g. CREATE, ALTER, etc)
3. Have other tables been created in the database?
4. If you do a fresh start with a different database and a more privileged MySQL user, do you get to the same result?
by
+1
1. all confirmed. Note that the error message is "table not found" instead of "connection failed", which means it can successfully connect to the database..
2. it's "root" user.
3. it's empty database, and still empty after Q2A start running.
4. root is highest privilege user, other name database still not work well.
by
edited by
+1
Interesting.

5. Aside from the database connection, have you changed anything else in qa-config.php? (e.g. QA_MYSQL_TABLE_PREFIX)
6. Have you added a new theme/plugin/language pack BEFORE installing Q2A? If so, please, retry with the ones distributed by the standard Q2A package
7. Does the setup succeed if you use Apache? (nginx is not really officially supported)
by
+1
5. nope.
6. nope.
7. nope.
I just unpack Q2A, rename files ".htaccess" and "qa-config.php", set db config in "qa-config.php" and access "index.php". Then I got same error.
by
I'm tried debug it and noticed it won't enter the line:
./qa-inluced/qa-index.php line 178: require QA_INCLUDE_DIR . 'qa-install.php';
it looks I need a way to tell the site install Q2A and initialize database.

2 Answers

+5 votes
by
selected by
 
Best answer

It seems a default setting in PHP has changed in PHP 8.1. Now, MySQL errors throw exceptions by default. That is an issue if the SQL statement is not wrapped in a try/catch clause.

This change should revert the behavior back to the one prior to PHP 8.1.

by
It works well!
by
edited by
This is working for me too but with an error message.
Please have a look here https://www.question2answer.org/qa/105300/could-causing-error-after-successfully-installation-xampp
by
That is not related to this fix. That is a different error that this current error didn't even allow you to see
+1 vote
by

Hello flithor,

Thank you for reporting this error. An update was released on July 5, 2023 (Question2Answer v1.8.7) that officially fixed this issue. If you are still facing this problem, updating your Question2Answer website is the simplest solution. What follows is a brief explanation on when this problem arose and how to fix it.

Q2A installation

Question2Answer has a mechanism for installing/updating/fixing its own database when needed; namely, when a database error arises, it runs a set of checks to determine whether one of those operations is needed.

When requesting a regular page on your website, like the homepage, the following lines at qa-include/qa-page.php are executed:

qa_db_connect('qa_page_db_fail_handler');
qa_initialize_postdb_plugins();

The first line is for connecting to the database and setting an error handling routine named qa_page_db_fail_handler; the second line loads Question2Answer plugins, which in turn loads the website options (settings from Q2A and plugins) from the database.

This error occurs because the table containing website options  ('q2a_db.qa_options') doesn't exist in a new Q2A installation. However, the error handler catches this error, confirms the database is actually empty, and finally proceeds with the installation process.

But if everything is functioning just alright, why does it stop working? The answer is in the latest PHP 8 updates which affects how Question2Answer get data (query) from database.

PHP 8 Updates

The function qa_db_query_execute runs database queries via $db, which is an instance of mysqli, in this manner:

$result = $db->query($query);

But, according to Salman's post, the MySQLi extention defaults to throwing exceptions, instead of just keeping errors silent, as of PHP 8.1. This new default behavior makes Q2A error handling method go off the normal course and throw a PHP exception.

Solution

pupi1985' answer and Salman's post agree on handling this situation by invoking mysqli_report(MYSQLI_REPORT_OFF)  before making the first MySQLi connection.

Tidbits

There are other errors or warnings related to PHP 8 updates; for example, just after fixing this issue, the following deprecation notice:

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated

was thrown after continuing with the installation process. These errors disappear after updating to Question2Answer v1.8.8.


I hope this clarification is helpful to you and the community. If you have any question about this subject, please leave a comment below Backhand index pointing down emoji or update your question with more details.

Take care, bye! Waving Hand Sign Emoji

...