|
Christoph Galuschka |
bad8eb |
#!/bin/sh
|
|
Christoph Galuschka |
bad8eb |
# Author: Athmane Madjoudj <athmanem@gmail.com>
|
|
Christoph Galuschka |
bad8eb |
# Author: Christoph Galuschka <christoph.galuschka@chello.at>
|
|
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."
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
# Install php-mysql-module
|
|
Christoph Galuschka |
bad8eb |
t_InstallPackage php-mysql
|
|
Christoph Galuschka |
bad8eb |
|
|
Christoph Galuschka |
bad8eb |
# we need a working and running mysql server
|
|
Christoph Galuschka |
bad8eb |
t_InstallPackage mysql-server
|
|
Christoph Galuschka |
bad8eb |
t_ServiceControl mysqld start >/dev/null 2>&1
|
|
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 |
bad8eb |
drop database 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 |
/bin/rm $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 |
|
|
Christoph Galuschka |
bad8eb |
\$dbconnect = mysql_connect("localhost","centos","qa");
|
|
Christoph Galuschka |
bad8eb |
if (!\$dbconnect)
|
|
Christoph Galuschka |
bad8eb |
{
|
|
Christoph Galuschka |
bad8eb |
die('Could not connect: ' . mysql_error());
|
|
Christoph Galuschka |
bad8eb |
}
|
|
Christoph Galuschka |
bad8eb |
mysql_select_db("phptests", \$dbconnect);
|
|
Christoph Galuschka |
bad8eb |
mysql_query("INSERT INTO tests (name)
|
|
Christoph Galuschka |
bad8eb |
VALUES ('phpsqltest')");
|
|
Christoph Galuschka |
bad8eb |
mysql_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 |
bad8eb |
t_Log FAIL
|
|
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 |
|
|
Christoph Galuschka |
bad8eb |
\$dbconnect = mysql_connect("localhost","centos","qa");
|
|
Christoph Galuschka |
bad8eb |
if (!\$dbconnect)
|
|
Christoph Galuschka |
bad8eb |
{
|
|
Christoph Galuschka |
bad8eb |
die('Could not connect: ' . mysql_error());
|
|
Christoph Galuschka |
bad8eb |
}
|
|
Christoph Galuschka |
bad8eb |
mysql_select_db("phptests", \$dbconnect);
|
|
Christoph Galuschka |
bad8eb |
\$array = mysql_query("SELECT count(*) as success FROM tests WHERE name = 'phpsqltest'");
|
|
Christoph Galuschka |
bad8eb |
mysql_close(\$dbconnect);
|
|
Christoph Galuschka |
bad8eb |
\$line = mysql_fetch_array(\$array, MYSQL_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 |
|