hiphop-php /hphp/test/zend/bad/ext/mysql/tests/mysql_query.php

Language PHP Lines 106
MD5 Hash 6720810b2bce298a9e3a86e2ae1dcd36 Estimated Cost $1,830 (why?)
Repository git://github.com/facebook/hiphop-php.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
<?php
include_once("connect.inc");

$tmp    = NULL;
$link   = NULL;

if (!is_null($tmp = @mysql_query()))
	printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

if (false !== ($tmp = @mysql_query($link)))
	printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

require('table.inc');

if (NULL !== ($tmp = @mysql_query("SELECT 1 AS a", $link, "foo")))
	printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);

if (false !== ($tmp = mysql_query('THIS IS NOT SQL', $link)))
	printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

if (false !== ($tmp = mysql_query("SELECT 'this is sql but with backslash g'\g", $link)))
	printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

if ((0 === mysql_errno($link)) || ('' == mysql_error($link)))
	printf("[006] mysql_errno()/mysql_error should return some error\n");

if (!$res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; ", $link))
	printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));

var_dump(mysql_fetch_assoc($res));
mysql_free_result($res);

if (!$res = mysql_query("SELECT 'a' AS ''", $link))
	printf("[007a] [%d] %s\n", mysql_errno($link), mysql_error($link));

var_dump($tmp = mysql_fetch_assoc($res));
var_dump($tmp[""]);
mysql_free_result($res);

if (false !== ($res = mysql_query("SELECT 'this is sql but with semicolon' AS valid ; SHOW VARIABLES", $link)))
	printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));

if (mysql_query('DROP PROCEDURE IF EXISTS p', $link)) {
	// let's try to play with stored procedures
	if (mysql_query('CREATE PROCEDURE p(OUT ver_param VARCHAR(25)) BEGIN SELECT VERSION() INTO ver_param; END;', $link)) {
		$res = mysql_query('CALL p(@version)', $link);
		$res = mysql_query('SELECT @version AS p_version', $link);
		$tmp = mysql_fetch_assoc($res);
		if (!isset($tmp['p_version']) || ('' == $tmp['p_version'])) {
			printf("[009] Result seems wrong, dumping\n");
			var_dump($tmp);
		}
		if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['p_version'])) {
			printf("[010] Expecting unicode string, dumping\n");
			var_dump($tmp);
		}
		mysql_free_result($res);
	} else {
		printf("[011] [%d] %s\n", mysql_errno($link), mysql_error($link));
	}

	mysql_query('DROP FUNCTION IF EXISTS f', $link);
	if (mysql_query('CREATE FUNCTION f( ver_param VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN ver_param;', $link)) {
		$res = mysql_query('SELECT f(VERSION()) AS f_version', $link);
		$tmp = mysql_fetch_assoc($res);
		if (!isset($tmp['f_version']) || ('' == $tmp['f_version'])) {
			printf("[012] Result seems wrong, dumping\n");
			var_dump($tmp);
		}
		if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp['f_version'])) {
			printf("[013] Expecting unicode string, dumping\n");
			var_dump($tmp);
		}
		mysql_free_result($res);
	} else {
		printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
	}
}

mysql_close($link);

if (false !== ($tmp = mysql_query("SELECT id FROM test", $link)))
	printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);

print "done!";
?>
<?php error_reporting(0); ?>
<?php
require_once('connect.inc');

// connect + select_db
if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
	printf("[clean] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
 	  $host, $myhost, $user, $db, $port, $socket);
}

if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
	printf("[clean] Failed to drop test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
}

/* MySQL server may not support this - ignore errors */
@mysql_query('DROP PROCEDURE IF EXISTS p', $link);
@mysql_query('DROP FUNCTION IF EXISTS f', $link);

mysql_close($link);
?>
Back to Top