You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
1.8 KiB

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