What is difference between the new mysqli
and mysqli_connect
?
I know that executing a query is different;
for example: mysqli->query()
and mysqli_query()
Why are there two different types, what is the need for the difference?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
One is for Procedural style programming and other is for OOP style programming. Both serve the same purpose; Open a new connection to the MySQL server
OOP Style usage
$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
Procedural Style usage
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'my_db');
Reference: PHP Manual
回答2:
Right on @Hanky Panky. I'd also add to that the PHP docs:
http://www.php.net/manual/en/mysqli.construct.php
Note:
OO syntax only: If a connection fails an object is still returned. To check if the connection failed then use either the mysqli_connect_error() function or the mysqli->connect_error property as in the preceding examples.
So error handling is just one difference.