I went through this guide and the code provided does not work. I run Drupal core 10.0.0-alpha4 with PHP8.1 and whenever I run the below code I get HTTP ERROR 500, which is a PHP error, the question is how to adjust this code and make it work with php8.1?
<?php
$db = mysql_connect('localhost','user','password');
if(!$db) echo "cannot connect to the database";
mysql_select_db('user_drpl1');
$result=mysql_query('OPTIMIZE TABLE accesslog,cache,comments,node,users,watchdog;');
echo mysql_error();
?>
The error message I get when I run this script:
Stack trace:
#0 {main}
thrown in /var/www/example.com/html/drupal/optimize.php on line 2" while reading response header from upstream, client: xx.xx.xxx, server: example.com, request: "GET /optimize.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.1-fpm.sock:", host: "example.com"
2022/05/28 17:54:57 [error] 897442#897442: *29717 FastCGI sent in stderr: "PHP message: PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /var/www/example.com/html/drupal/optimize.php:2