質問

I moved from Xamp on a windows computer to Mamp on Mac. And Php version moved tom 5.4.19 to 5.5.3. I exported and imported my Mysql database and it worked fine. But when I lunched .php files working perfectly in the Xamp they give me error now like the following

    Notice: Use of undefined constant “root†- assumed '“rootâ€' in /Applications/MAMP/htdocs/2_Documents/upload.php on line 20

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /Applications/MAMP/htdocs/2_Documents/upload.php on line 20

Warning: mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /Applications/MAMP/htdocs/2_Documents/upload.php on line 20
Access denied for user 'root'@'localhost' (using password: YES)

it seem that one issue is the fact that Mysql_connect(): working on the old server is not anymore accepted. How can I manage the script upgrade smoothly? without write back all the code?

役に立ちましたか?

解決

You have a different php configuration which displays warnings that you probably had suppressed before. Most likely you also use a newer php version now.

  • The first notice is about a syntax error in strict mode, you probably forgot quotes around a literal string. That might also indicate a character encoding issue, but we cannot tell with the little information you provide.
  • The second one speaks for itself: the old mysql extension has been deprecated. Port your code to the newer (and safer) mysqli extension or PDO. Start using "prepared statements" which prevent security issues like "sql injection". Consult google for examples or the excellent php documentation.
  • About the connection error: nothing we can say about your credentials... Looks like you used a totally open mysql server and the mysql root account on the old system. You should not do that. Apparently the newer system is a little more closed in that aspect which is a good idea.

When you solved those issues you should reconfigure php to not display errors and warnings at all, since they disrupt your output. Use phps logging facilities instead, especially at production sites.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top