I get Fatal error

When I deploy my php web app, I constantly get this error:

" Fatal error : Uncaught mysqli_sql_exception: No such file or directory in /app/index.php:12 Stack trace: #0 /app/index.php(12): mysqli->__construct(‘localhost’, ‘TuDe2’, Object(SensitiveParameterValue), ‘tuna_3’) #1 {main} thrown in /app/index.php on line 12"

What should I do?
Please help me…

Hey @TunaDe,
welcome to Kinsta Community!
Does your application require a database? If so, you must create one using our DB hosting or an external database. By reviewing the short error it seems the code is trying to reach a MySQL instance in localhost.

Regards,
Alessandro

Dear @Alessandro,
I already created a database and linked it to my app.
But I continously get this error.

That’s great, please double check the credentials you are using, the hostname will not be ‘localhost’. You can find the details inside your Database Info page in MyKinsta, after clicking the Connection details button:

I changed my “$host” info in index.php file according to my credential, but I still get this error.

Sorry, I get this error:
" Fatal error : Uncaught mysqli_sql_exception: Table ‘tuna_3.products’ doesn’t exist in /app/index.php:30 Stack trace: #0 /app/index.php(30): mysqli->query(‘SELECT * FROM p…’) #1 {main} thrown in /app/index.php on line 30"

Cool, now the error has changed and it seems that the app can connect to the Database. The error reported shows that your code is looking for a table called products in your tuna_3 database but the table isn’t there.
I am not a developer but I think that you can either edit your code so that the table gets automatically created if not found or you can first access the database and create the table manually.

Regards,
Alessandro

Do I have to change the “localhost” part in MySQL Workbench to the one stated in Connection details?

If you are using a MySQL client you will need to use the external connection details. These can still be found in the same Info page of MyKinsta

I externally connected MySQL table according to my external connection details.
I get this error now:

" Warning : mysqli::__construct(): Error while reading greeting packet. PID=50 in /app/index.php on line 12

Fatal error : Uncaught mysqli_sql_exception: MySQL server has gone away in /app/index.php:12 Stack trace: #0 /app/index.php(12): mysqli->__construct(‘tuna3-2n8yu-mys…’, ‘TuDe2’, Object(SensitiveParameterValue), ‘tuna_3’) #1 {main} thrown in /app/index.php on line 12"

Hi there :wave:

I’m not a programmer either, but could you please tell what’s exactly stated in that /app/index.php file on line 12 ? (Note: if it contains your DB user/password, please redact it before you post it here).

Also wondering if the script tried to perform mysqli() PHP function? and if you used those variables provided in the “Environment Variables” in your “Application → Settings page” in that mysqli connection string)?

Were you able to connect to that Database server directly/remotely from your local machine (using any 3rd tools, like DBeaver, MySQL Workbench, etc.)? And were you also able to perform the same SQL commands (that are used in your PHP script) with that 3rd party tool from your local machine?
If you were able to connect to it (remotely) from your local machine, and were able to perform SQL commands there, then we can tell everything is working fine and we can rule out your Database server - and probably there’s something with the PHP scripts/codes you have in your application that need to be fixed/changed.

Best regards,
Agus

Dear Agus,
I could connect from MySQL Workbench before I changed host credentials according to my MyKinsta information page.

What’s exactly stated in that /app/index.php file on line 12 is:
“$mysqli = new mysqli($host, $user, $pass, $db);”

Hey @TunaDe,

where did you set the variables $host, $user, $pass and $db? If you have set those variables in MyKinsta you will need to call them differently:

Regards,
Alessandro