问题
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