Blame tests/p_php/25-php-mysql55-test.sh

Christoph Galuschka 8b8d57
#!/bin/sh
Christoph Galuschka 975f89
# Author: Athmane Madjoudj <athmanem@gmail.com>
Christoph Galuschka 975f89
# Author: Christoph Galuschka <tigalch@tigalch.org>
Christoph Galuschka 975f89
# reusing the script from LAMP-Tests
Christoph Galuschka 975f89
Christoph Galuschka bf2284
t_Log "Running $0 - php-cli basic interaction with mysql55 test."
Christoph Galuschka bf2284
if [ $centos_ver != 5 ]
Christoph Galuschka bf2284
then
Christoph Galuschka bf2284
  t_Log "This is not a C5-system - skipping"
Christoph Galuschka bf2284
  exit 0
Christoph Galuschka bf2284
fi
Christoph Galuschka 975f89
Christoph Galuschka 975f89
# Install php-mysql-module
Christoph Galuschka 975f89
t_InstallPackage php-mysql
Christoph Galuschka 975f89
Christoph Galuschka 975f89
# we need a working and running mysql server
Christoph Galuschka 975f89
#starting with 5.10 we need to reflect mysql55
Christoph Galuschka bf2284
t_ServiceControl mysqld stop
Christoph Galuschka bf2284
t_ServiceControl mysql55-mysqld start >/dev/null 2>&1
Christoph Galuschka 975f89
Christoph Galuschka 975f89
#create a little DB to use
Christoph Galuschka 975f89
CREATE='/var/tmp/mysql-php-QA.sql'
Christoph Galuschka 975f89
Christoph Galuschka 975f89
cat >$CREATE <
Christoph Galuschka 975f89
drop database if exists phptests;
Christoph Galuschka 975f89
create database phptests;
Christoph Galuschka 975f89
use phptests;
Christoph Galuschka 975f89
create table tests (name varchar(20)) ;
Christoph Galuschka 975f89
grant all on phptests.* to 'centos'@'localhost' identified by 'qa';
Christoph Galuschka 975f89
flush privileges;
Christoph Galuschka 975f89
EOF
Christoph Galuschka 975f89
Christoph Galuschka 975f89
mysql <$CREATE
Christoph Galuschka 975f89
Christoph Galuschka 975f89
# create PHP Script and write something into DB
Christoph Galuschka 975f89
INSERT='/var/tmp/test.php'
Christoph Galuschka 975f89
Christoph Galuschka 975f89
cat >$INSERT <
Christoph Galuschka 975f89
Christoph Galuschka 975f89
\$dbconnect = mysql_connect("localhost","centos","qa");
Christoph Galuschka 975f89
if (!\$dbconnect)
Christoph Galuschka 975f89
  {
Christoph Galuschka 975f89
  die('Could not connect: ' . mysql_error());
Christoph Galuschka 975f89
  }
Christoph Galuschka 975f89
mysql_select_db("phptests", \$dbconnect);
Christoph Galuschka 975f89
mysql_query("INSERT INTO tests (name)
Christoph Galuschka 975f89
VALUES ('phpsqltest')");
Christoph Galuschka 975f89
mysql_close(\$dbconnect);
Christoph Galuschka 975f89
?> 
Christoph Galuschka 975f89
EOF
Christoph Galuschka 975f89
Christoph Galuschka 975f89
php $INSERT
Christoph Galuschka 975f89
if [ $? -ne 0 ]
Christoph Galuschka 975f89
  then
Christoph Galuschka 975f89
  t_Log "Inserting into DB failed"
Christoph Galuschka 975f89
  exit 1
Christoph Galuschka 975f89
fi
Christoph Galuschka 975f89
Christoph Galuschka 975f89
# create PHP script to read from DB
Christoph Galuschka 975f89
READ='/var/tmp/read.php'
Christoph Galuschka 975f89
cat >$READ <
Christoph Galuschka 975f89
Christoph Galuschka 975f89
\$dbconnect = mysql_connect("localhost","centos","qa");
Christoph Galuschka 975f89
if (!\$dbconnect)
Christoph Galuschka 975f89
  {
Christoph Galuschka 975f89
  die('Could not connect: ' . mysql_error());
Christoph Galuschka 975f89
  }
Christoph Galuschka 975f89
mysql_select_db("phptests", \$dbconnect);
Christoph Galuschka 975f89
\$array = mysql_query("SELECT count(*) as success FROM tests WHERE name = 'phpsqltest'");
Christoph Galuschka 975f89
mysql_close(\$dbconnect);
Christoph Galuschka 975f89
\$line = mysql_fetch_array(\$array, MYSQL_ASSOC);
Christoph Galuschka 975f89
print \$line['success'];
Christoph Galuschka 975f89
?>
Christoph Galuschka 975f89
EOF
Christoph Galuschka 975f89
Christoph Galuschka 975f89
# If we execute the script and get '1' it works (1 entry should be in the DB)
Christoph Galuschka 975f89
php $READ | grep -q '1'
Christoph Galuschka 975f89
Christoph Galuschka 975f89
t_CheckExitStatus $?
Christoph Galuschka 975f89
Christoph Galuschka 975f89
#cleaning up
Christoph Galuschka 975f89
/bin/rm $READ $CREATE $INSERT
Christoph Galuschka 975f89
mysql -u root -e 'drop database phptests' >/dev/null 2>&1