How are mysqli_connect Arguments optional?

那年仲夏 提交于 2020-05-09 10:04:32

问题


According to w3schools.com, all the arguments of the mysqli_connect function are optional:

mysqli_connect($host,$username,$password,$dbname,$port,$socket);

What does it mean to be 'Optional'? What don't I understand is how can we skip any of those values and let it use the default values?

Thanks in advance.


回答1:


You can specify default MySQL credentials straight in the php.ini configuration file.

Please see http://php.net/manual/en/mysqli.configuration.php#ini.mysqli.default-port as a reference.

Then, if you call mysqli_connect(), the connection still will be made using those settings from php.ini (assuming they are correct of course).

Unless what you don't understand is the idea of default arguments? Sorry if I am wrong but I couldn't clearly figure it out from your question. If that is the case please: http://php.net/manual/en/functions.arguments.php#functions.arguments.default




回答2:


Ok, I figured it myself. This was totally a noob one. Since mysqli_connect takes in different strings as its arguments, 'Optional' (and hence skipping an argument) means providing empty string ("")as argument, in which case it uses the default values.



来源:https://stackoverflow.com/questions/46094468/how-are-mysqli-connect-arguments-optional

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!