philip / MySQLConverterTool

A MySQL Converter Tool
314 stars 144 forks source link

Converter skipped mysql_set_charset function #13

Closed semoriil closed 8 years ago

semoriil commented 8 years ago

Was

  $link = mysql_connect(HostName, UserName, Password);
  if (!$link)
  {
    exit("Error connecting to DB! " . mysql_error());
  }
  mysql_select_db(DBName, $link);
  if (!mysql_set_charset('utf8', $link))
    echo 'Setting charset error: ' . mysql_error();

converted to

  $link = ($GLOBALS["___mysqli_ston"] = mysqli_connect(HostName,  UserName,  Password));
  if (!$link)
  {
    exit("Error connecting to DB! " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
  }
  ((bool)mysqli_query( $link, "USE " . constant('DBName')));
  if (!mysql_set_charset('utf8', $link))
    echo 'Setting charset error: ' . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false));

Shoul be replaced with something like

...
if ((!is_object($GLOBALS["___mysqli_ston"])) || !mysqli_set_charset ( $GLOBALS["___mysqli_ston"], 'utf8' ))
...
LukeMcLachlan commented 8 years ago

when you pass these through the converted are you wrapping them in <?php ... ?> ?

semoriil commented 8 years ago

Yes. Some files use short tags <? ... ?> but not this one. If you check Converter.php of this project you can see there is no convertion for mysql_set_charset. It's not big problem for me - i call it only once for whole my project - but anyway...

LukeMcLachlan commented 8 years ago

I must admit I gave this conversion tool a go last night and it worked very well. However in the end I decided to make the changes myself because I didn't like the globals being set. Took a lot longer but the end result is a lot cleaner.

SergeAx commented 8 years ago

I confirm this issue.

philip commented 8 years ago

This was fixed via pull request #17 -- thank you for filing this bug report!