|
Christoph Galuschka |
bad8eb |
#!/bin/sh
|
|
Christoph Galuschka |
bad8eb |
# Author: Athmane Madjoudj <athmanem@gmail.com>
|
|
Christoph Galuschka |
376560 |
# Author: Christoph Galuschka <tigalch@tigalch.org>
|
|
Christoph Galuschka |
bad8eb |
# reusing the script from LAMP-Tests
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
t_Log "Running $0 - php-cli basic interaction with mysql test."
|
|
|
ecf875 |
t_SkipReleaseGreaterThan 7 'use module-aware tests instead'
|
|
Christoph Galuschka |
bad8eb |
|
|
|
7a357b |
# Install php-mysql/php-mysqld module depending on version
|
|
Christoph Galuschka |
bad8eb |
# we need a working and running mysql server
|
|
Christoph Galuschka |
376560 |
#starting with 5.10 we need to reflect mysql55
|
|
Christoph Galuschka |
376560 |
if [ $centos_ver = 5 ]
|
|
Christoph Galuschka |
376560 |
then
|
|
|
7a357b |
t_InstallPackage mysql-server mysql55-mysql-server nc php-mysql
|
|
Christoph Galuschka |
b5edf2 |
t_ServiceControl mysql55-mysqld stop
|
|
Rene Diepstraten |
acb41a |
t_ServiceControl mysqld start >/dev/null 2>&1
|
|
Rene Diepstraten |
bbeceb |
elif [ $centos_ver = 6 ]
|
|
Rene Diepstraten |
bbeceb |
then
|
|
|
7a357b |
t_InstallPackage mysql-server nc php-mysql
|
|
Rene Diepstraten |
acb41a |
t_ServiceControl mysqld start >/dev/null 2>&1
|
|
Rene Diepstraten |
bbeceb |
else
|
|
|
7a357b |
t_InstallPackage mariadb-server nc php-mysqlnd
|
|
Rene Diepstraten |
acb41a |
t_ServiceControl mariadb start >/dev/null 2>&1
|
|
Christoph Galuschka |
376560 |
fi
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
#create a little DB to use
|
|
Christoph Galuschka |
bad8eb |
CREATE='/var/tmp/mysql-php-QA.sql'
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
cat >$CREATE <
|
|
Christoph Galuschka |
d4b6ff |
drop database if exists phptests;
|
|
Christoph Galuschka |
bad8eb |
create database phptests;
|
|
Christoph Galuschka |
bad8eb |
use phptests;
|
|
Christoph Galuschka |
bad8eb |
create table tests (name varchar(20)) ;
|
|
Christoph Galuschka |
bad8eb |
grant all on phptests.* to 'centos'@'localhost' identified by 'qa';
|
|
Christoph Galuschka |
bad8eb |
flush privileges;
|
|
Christoph Galuschka |
bad8eb |
EOF
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
mysql <$CREATE
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
# create PHP Script and write something into DB
|
|
Christoph Galuschka |
bad8eb |
INSERT='/var/tmp/test.php'
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
cat >$INSERT <
|
|
Christoph Galuschka |
bad8eb |
|
|
Pablo Greco |
e9f184 |
\$dbconnect = mysqli_connect("localhost","centos","qa");
|
|
Christoph Galuschka |
bad8eb |
if (!\$dbconnect)
|
|
Christoph Galuschka |
bad8eb |
{
|
|
Pablo Greco |
e9f184 |
die('Could not connect: ' . mysqli_error());
|
|
Christoph Galuschka |
bad8eb |
}
|
|
Pablo Greco |
e9f184 |
mysqli_select_db(\$dbconnect, "phptests");
|
|
Pablo Greco |
e9f184 |
mysqli_query(\$dbconnect, "INSERT INTO tests (name)
|
|
Christoph Galuschka |
bad8eb |
VALUES ('phpsqltest')");
|
|
Pablo Greco |
e9f184 |
mysqli_close(\$dbconnect);
|
|
Christoph Galuschka |
bad8eb |
?>
|
|
Christoph Galuschka |
bad8eb |
EOF
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
php $INSERT
|
|
Christoph Galuschka |
bad8eb |
if [ $? -ne 0 ]
|
|
Christoph Galuschka |
bad8eb |
then
|
|
Christoph Galuschka |
518959 |
t_Log "Inserting into DB failed"
|
|
Christoph Galuschka |
bad8eb |
exit 1
|
|
Christoph Galuschka |
bad8eb |
fi
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
# create PHP script to read from DB
|
|
Christoph Galuschka |
bad8eb |
READ='/var/tmp/read.php'
|
|
Christoph Galuschka |
bad8eb |
cat >$READ <
|
|
Christoph Galuschka |
bad8eb |
|
|
Pablo Greco |
e9f184 |
\$dbconnect = mysqli_connect("localhost","centos","qa");
|
|
Christoph Galuschka |
bad8eb |
if (!\$dbconnect)
|
|
Christoph Galuschka |
bad8eb |
{
|
|
Pablo Greco |
e9f184 |
die('Could not connect: ' . mysqli_error());
|
|
Christoph Galuschka |
bad8eb |
}
|
|
Pablo Greco |
e9f184 |
mysqli_select_db(\$dbconnect, "phptests");
|
|
Pablo Greco |
e9f184 |
\$array = mysqli_query(\$dbconnect, "SELECT count(*) as success FROM tests WHERE name = 'phpsqltest'");
|
|
Pablo Greco |
e9f184 |
mysqli_close(\$dbconnect);
|
|
Pablo Greco |
e9f184 |
\$line = mysqli_fetch_array(\$array, MYSQLI_ASSOC);
|
|
Christoph Galuschka |
bad8eb |
print \$line['success'];
|
|
Christoph Galuschka |
bad8eb |
?>
|
|
Christoph Galuschka |
bad8eb |
EOF
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
# If we execute the script and get '1' it works (1 entry should be in the DB)
|
|
Christoph Galuschka |
bad8eb |
php $READ | grep -q '1'
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
t_CheckExitStatus $?
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
518959 |
#cleaning up
|
|
Christoph Galuschka |
518959 |
/bin/rm $READ $CREATE $INSERT
|
|
Christoph Galuschka |
975f89 |
mysql -u root -e 'drop database phptests' >/dev/null 2>&1
|