晓夏

北漂的女孩

Good Luck To You!

mysql数据连接方式

浏览量:392

1.以下是从命令行中连接mysql服务器的简单实例:

[root@host]# mysql -u root -p  Enter password:******

退出 mysql> 命令提示窗口可以使用 exit 命令,如下所示:

mysql> exit Bye

2、使用 PHP 脚本连接 MySQL

语法:

connection mysql_connect(server,user,passwd,new_link,client_flag);

你可以使用PHP的 mysql_close() 函数来断开与MySQL数据库的链接。

语法:

bool mysql_close ( resource $link_identifier );

3.例子

<html>
<head>
<title>Connecting MySQL Server</title>
</head>
    <body>
        <?php
           $dbhost = 'localhost:3306';  //mysql服务器主机地址
           $dbuser = 'guest';      //mysql用户名
           $dbpass = 'guest123';//mysql用户名密码
           $conn = mysql_connect($dbhost, $dbuser, $dbpass);
           if(! $conn )
           {
             die('Could not connect: ' . mysql_error());
           }
           echo 'Connected successfully';
           mysql_close($conn);
        ?>
    </body>
</html>

神回复

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。