| #!/bin/sh |
| |
| |
| |
| |
| t_Log "Running $0 - php-cli basic interaction with mysql test." |
| |
| |
| t_InstallPackage php-mysql |
| |
| |
| t_InstallPackage mysql-server |
| t_ServiceControl mysqld start >/dev/null 2>&1 |
| |
| |
| CREATE='/var/tmp/mysql-php-QA.sql' |
| |
| cat >$CREATE <<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 |
| |
| mysql <$CREATE |
| |
| |
| INSERT='/var/tmp/test.php' |
| |
| cat >$INSERT <<EOF |
| <?php |
| \$dbconnect = mysql_connect("localhost","centos","qa"); |
| if (!\$dbconnect) |
| { |
| die('Could not connect: ' . mysql_error()); |
| } |
| mysql_select_db("phptests", \$dbconnect); |
| mysql_query("INSERT INTO tests (name) |
| VALUES ('phpsqltest')"); |
| mysql_close(\$dbconnect); |
| ?> |
| EOF |
| |
| php $INSERT |
| if [ $? -ne 0 ] |
| then |
| t_Log "Inserting into DB failed" |
| exit 1 |
| fi |
| |
| |
| READ='/var/tmp/read.php' |
| cat >$READ <<EOF |
| <?php |
| \$dbconnect = mysql_connect("localhost","centos","qa"); |
| if (!\$dbconnect) |
| { |
| die('Could not connect: ' . mysql_error()); |
| } |
| mysql_select_db("phptests", \$dbconnect); |
| \$array = mysql_query("SELECT count(*) as success FROM tests WHERE name = 'phpsqltest'"); |
| mysql_close(\$dbconnect); |
| \$line = mysql_fetch_array(\$array, MYSQL_ASSOC); |
| print \$line['success']; |
| ?> |
| EOF |
| |
| |
| php $READ | grep -q '1' |
| |
| t_CheckExitStatus $? |
| |
| |
| /bin/rm $READ $CREATE $INSERT |