I found the solution by logging into the site FTP, renaming my WP site's index.php to index.php_, and supplying this code in a new index.php file:
$servername = "xxx.xxx.xxx.xxx";
$username = "xxxxx";
$password = "xxxxx";
$conn = new PDO("mysql:host=$servername;dbname=xxxxxx", $username, $password);
// set the PDO error mode to exception
echo "Connected successfully";
echo "Connection failed: " . $e->getMessage();
This gave a far more meaningful error message, saying that access was denied for my user. So I entered phpmyadmin, and ran a query to find the host name, and then called nslookup in a terminal with that host name as argument. And lo and behold, the web hosting had changed the database server IP address (I had tried to work with just the hostname, but this being a shared hosting and me using a temporary URL seems to botch that way of doing it).
So I fixed the IP address and I finally could connect and populate my forms in Wordpress using the database.