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
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.
My guess it's related to one of these 2 lines:
You can try to debug it locally, change those lines and see what happens.
Hi,
Applied rules:
These is what rector reports.
I will try to debug as per your input
This should be solved by https://github.com/rectorphp/rector/pull/4119
Thanks :+1:
Most helpful comment
Hi,
Thanks for getting back so quickly.
The expected output is:
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