Edit report at http://bugs.php.net/bug.php?id=55001&edit=1

 ID:                 55001
 Updated by:         [email protected]
 Reported by:        enrico dot triolo at gmail dot com
 Summary:            Mysql explain command with prepared statement
-Status:             Open
+Status:             Feedback
 Type:               Bug
 Package:            MySQLi related
 Operating System:   Ubuntu 11.04
 PHP Version:        Irrelevant
-Assigned To:        
+Assigned To:        mysql
 Block user comment: N
 Private report:     N

 New Comment:

Are you using mysqlnd or libmysql. If libmysql which version? (check phpinfo() 
output or `php --ri mysqli` from command line)


Previous Comments:
------------------------------------------------------------------------
[2011-06-06 16:30:24] enrico dot triolo at gmail dot com

Description:
------------
Hi, I found out an anomaly executing an "explain" command using prepared 

statements functions. Using "standard" functions works as expected.

In short, if I execute an "explain" on a query with a subquery and fetch the 

resulting "type" field, I get "unique_subq" instead of "unique_subquery".

Please view the attached code snippet.

I'm using PHP 5.3.5-1ubuntu7.2, but other versions have the same behaviour too.



The attached script uses a table created with this instruction:

CREATE TABLE IF NOT EXISTS `mytest_table` (

  `id` int(11) NOT NULL AUTO_INCREMENT,

  `idParent` int(11) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Test script:
---------------
$sql = 'explain SELECT id FROM mytest_table WHERE idParent <> -1 AND idParent 
NOT IN ( SELECT id FROM mytest_table)';

$link = mysqli_connect("localhost", 'user', 'password', 'dbName');

printf("Using prepared statement functions...\n");

$stmt = mysqli_stmt_init($link);

mysqli_stmt_prepare($stmt, $sql);

mysqli_stmt_execute($stmt);

mysqli_stmt_store_result($stmt);

$result = mysqli_stmt_result_metadata($stmt);

printf("Fields:\n");

while($field = mysqli_fetch_field($result))

        printf("\t%s(%d)\n", $field->name, $field->length);

mysqli_free_result($result);

mysqli_stmt_bind_result($stmt, $id, $select_type, $table, $type, 
$possible_keys, $key, $key_len, $ref, $rows, $extra);

while(mysqli_stmt_fetch($stmt))

        printf("Type field value: %s\n", $type);

printf("\nUsing mysqli_query...\n");

$result = mysqli_query($link, $sql);

while($row = mysqli_fetch_array($result))

        printf("Type field value: %s\n", $row['type']);

mysqli_free_result($result);

mysqli_close($link);

Expected result:
----------------
Using prepared statement functions I'd expect the second row value for the 
"type" 

field being "unique_subquery".

Actual result:
--------------
I get "unique_subq" instead of "unique_subquery". Using mysqli_query (i.e. 

without prepared statement functions), I get the expected result:



Using prepared statement functions...

...

Type field value: unique_subq



Using mysqli_query...

...

Type field value: unique_subquery


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=55001&edit=1

Reply via email to