Blame tests/p_php_7.2/20_php_mariadb.sh

ecf875
#!/bin/bash
ecf875
ecf875
t_Log "Running $0 - PHP/MariaDB interaction"
ecf875
t_SkipReleaseLessThan 8 'no modularity'
ecf875
ecf875
t_EnableModuleStream php:7.2
ecf875
t_InstallPackageMinimal php-cli php-mysqlnd mariadb-server
ecf875
ecf875
t_Log "starting mariadb service"
ecf875
systemctl --quiet start mariadb
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_Log "create a test database"
ecf875
mysql << EOF
ecf875
DROP DATABASE IF EXISTS phptests;
ecf875
CREATE DATABASE phptests;
ecf875
USE phptests;
ecf875
CREATE TABLE tests (name VARCHAR(20));
ecf875
GRANT ALL ON phptests.* TO 'centos'@'localhost' IDENTIFIED BY 'qa';
ecf875
FLUSH PRIVILEGES;
ecf875
EOF
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_Log "write to test database via PHP"
ecf875
php << EOF &> /dev/null
ecf875
ecf875
\$dbconnect = mysqli_connect("localhost", "centos", "qa");
ecf875
if (!\$dbconnect) {
ecf875
    die('Could not connect: ' . mysqli_error());
ecf875
}
ecf875
mysqli_select_db(\$dbconnect, "phptests");
ecf875
mysqli_query(\$dbconnect, "INSERT INTO tests (name) VALUES ('phpsqltest')");
ecf875
mysqli_close(\$dbconnect);
ecf875
?>
ecf875
EOF
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_Log "read from test database via PHP"
ecf875
php << EOF | grep -q '1'
ecf875
ecf875
\$dbconnect = mysqli_connect("localhost", "centos", "qa");
ecf875
if (!\$dbconnect) {
ecf875
    die('Could not connect: ' . mysqli_error());
ecf875
}
ecf875
mysqli_select_db(\$dbconnect, "phptests");
ecf875
\$array = mysqli_query(\$dbconnect, "SELECT count(*) AS success FROM tests WHERE name = 'phpsqltest'");
ecf875
mysqli_close(\$dbconnect);
ecf875
\$line = mysqli_fetch_array(\$array, MYSQLI_ASSOC);
ecf875
print \$line['success'];
ecf875
?>
ecf875
EOF
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_Log "stopping mariadb service"
ecf875
systemctl --quiet stop mariadb
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_Log "deleting database files"
ecf875
find /var/lib/mysql -mindepth 1 -delete
ecf875
t_CheckExitStatus $?
ecf875
ecf875
t_RemovePackage php-cli php-mysqlnd mariadb-server
ecf875
t_ResetModule php httpd nginx mariadb