Rector: Weird behaviour for mysql-to-mysqli set

Created on 24 Jul 2020  路  9Comments  路  Source: rectorphp/rector

Hi,
Have a test file (name testing.php) with code

<?php

mysql_query($sql, $dbx);
$res = mysql_query($sql2, $dbx);

Ran the following command
vendor\bin\rector process testing.php --set mysql-to-mysqli --dry-run

Produces this output

Rector v0.7.53

 5/5 [============================] 100%

1 file with changes
===================

1) testing.php

    ---------- begin diff ----------
--- Original
+++ New
@@ -1,4 +1,4 @@
 <?php

-mysql_query($sql, $dbx);
-$res = mysql_query($sql2, $dbx);
+mysql_query($dbx, $sql);
+$res = mysqli_query($res, $dbx, $sql2);
    ----------- end diff -----------


Applied rules:

 * Rector\Core\Rector\Argument\SwapFuncCallArgumentsRector
 * Rector\MysqlToMysqli\Rector\FuncCall\MysqlQueryMysqlErrorWithLinkRector
 * Rector\Renaming\Rector\Function_\RenameFunctionRector

The code is wrong
$res = mysqli_query($res, $dbx, $sql2);

Why $res is made a part of the argument list for mysqli_query when the function has originally two variables only.

Please do check and advise.

Regards
Kunal Bedi

bug

Most helpful comment

Hi,
Thanks for getting back so quickly.

The expected output is:

<?php

mysqli_query($dbx, $sql);
$res = mysqli_query($dbx, $sql2);

Basically the line:
$res = mysql_query($sql2, $dbx);
Should become:
$res = mysqli_query($dbx, $sql2);

but the output is taking the assigned variable of the statement $res and putting it in the function call as a first parameter while also swapping the two original variables like it should and giving:

$res = mysqli_query($res, $dbx, $sql2);

This is absolutely wrong as mysqli_query() function only take two parameters mysqli_query($db-link, $sql-statement).

My dev environment is:
Windows 10
Latest composer
rector/rector current version

Looking forward to hearing from you.

Regards
Kunal Bedi

All 9 comments

Hi,

what is expected output code?

Hi,
Thanks for getting back so quickly.

The expected output is:

<?php

mysqli_query($dbx, $sql);
$res = mysqli_query($dbx, $sql2);

Basically the line:
$res = mysql_query($sql2, $dbx);
Should become:
$res = mysqli_query($dbx, $sql2);

but the output is taking the assigned variable of the statement $res and putting it in the function call as a first parameter while also swapping the two original variables like it should and giving:

$res = mysqli_query($res, $dbx, $sql2);

This is absolutely wrong as mysqli_query() function only take two parameters mysqli_query($db-link, $sql-statement).

My dev environment is:
Windows 10
Latest composer
rector/rector current version

Looking forward to hearing from you.

Regards
Kunal Bedi

Just edited some obvious errors in my message above. Had forgotten to take coffee before writing it in. LOL
Thank you Tomas for being so prompt.

I'm not sure when I get to it.

What rule is actually causing it? It should be in the Rector output, under the changed code.

Hi,

Applied rules:

  • Rector\Core\Rector\Argument\SwapFuncCallArgumentsRector
  • Rector\MysqlToMysqli\Rector\FuncCall\MysqlQueryMysqlErrorWithLinkRector
  • Rector\Renaming\Rector\Function_\RenameFunctionRector

These is what rector reports.

I will try to debug as per your input

Thanks :+1:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

carusogabriel picture carusogabriel  路  5Comments

sidux picture sidux  路  5Comments

pavarnos picture pavarnos  路  4Comments

HDVinnie picture HDVinnie  路  3Comments

JanMikes picture JanMikes  路  3Comments