PHP5连接MYSQL出现错误的解决!

anyhih 2004-12-06 05:47:08
3.3.2 mysqli: Making a Connection
Under mysqli there are two different ways to connect to MySQL: the familiar mysqli_connect( ) and a new method, mysqli_real_connect( ).

Don't feel that mysqli_real_connect( ) is somehow superior to mysqli_connect( ) because it contains the word real. It's not. This name comes simply from the underlying MySQL C API. Besides, mysqli_connect( ) uses the same C functions as mysqli_real_connect( ); it just wraps them in an easy-to-use form.

Unfortunately, while mysqli_connect( ) looks similar to mysql_connect( ), it is not identical. For one, it now takes six parameters, all of them still optional:

mysqli_connect(hostname, username, password, database, port, socket)


The first three options—hostname, username, and password—are the same as mysql_connect( ), but the remaining three are different. The database parameter controls which database you want to query. Using this parameter is the same as calling mysql_select_database( ). This function is still available as mysqli_select_database( ), but you should not need to use it unless you are reusing the same connection to switch from one database to another on the same server.

The port option controls which port to contact on the database server, and socket specifies which socket to use. This is identical to adding :port or :/path/to/socket after the hostname in mysql_connect( ). (You cannot use this syntax in mysqli.) These two parameters are mutually exclusive. If you use one, there's no purpose in using the other.

Here's an example that uses the first five options:

mysqli_connect('db.example.org', 'web', 'xyz@123', 'users', 3306);

...全文
87 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
anyhih 2004-12-06
  • 打赏
  • 举报
回复
没时间详细解释,晚上再来

21,887

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧