Changing from mysql to mysqli code error

前端 未结 2 773
滥情空心
滥情空心 2021-01-14 19:56

I\'m changing over a lot of files from mysql to mysqli. I\'m using this to do it: https://wikis.oracle.com/display/mysql/Converting+to+MySQLi

My connect file (I\'ve

2条回答
  •  时光说笑
    2021-01-14 20:09

    14 [Line 14] Please check your code for parse errors, we failed to parse " ". Conversion will be incomplete!".

    This error is caused by the space before the ( in your mysql_connect() call. Replacing it with $conn=mysql_connect("$localhost", "$dbusername", "$dbpass"); removes this warning output by MySQLConverterTool.

    The remaining two errors are things that you should deal with by actually looking, yourself, at the difference between mysql_connect() and mysqli_connect(). mysql_connect()’s first argument, $server, can be formatted like hostname:port whereas with mysqli_connect() you would pass only hostname to its first argument and pass port as an optional fifth parameter. Also, mysqli would have you specify the database in the mysqli_connect() call instead of having a separate function analogous to mysql_select_db().

    I suggest that, if you need, you use the converter tool to convert all of your sourcecode from mysql to mysqli except for these lines with the warnings in them. Only you know what format "$localhost" comes in: if it might contain port information, you must separate the port information out. You should probably set the database to use in mysqli_connect() instead of using the converter’s automatic USE $db shim. This is exactly what the converter is trying to tell you :-).

    Just to note, I would not say:

    My connect file (I've taken out what I think is unnecessary code such as error handling for simplicity) creates errors that I'm not sure how to fix.

    The above suggests that the PHP code generated by the converter is, itself, throwing PHP warnings and errors at runtime (not that the converter is complaining about your original code or informing you that you need to actually do some manual conversion as I discussed above). That is why we were looking for errors like the once-missing semicolon which you corrected.

提交回复
热议问题