MySQL启动连接的命令以及与PHP程序连接的基本语法 |
使用mysql二进制方式启动连接 [root@host]# mysql -u root -p Enter password:****** 在登录成功后会出现 mysql> 命令提示窗口,你可以在上面执行任何 SQL 语句 。 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2854760 to server version: 5.0.9 Type help; or \h for help. Type \c to clear the buffer. 在以上实例中,我们使用了root用户登录到mysql服务器,当然你也可以使用其他mysql用户登录 。 mysql> exit Bye
connection mysql_connect(server,user,passwd,new_link,client_flag); 参数说明:
bool mysql_close ( resource $link_identifier ); 本函数关闭指定的连接标识所关联的到 MySQL 服务器的非持久连接 。如果没有指定 link_identifier,则关闭上一个打开的连接 。 <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> PHP调用MySQL的函数
以下实例展示了PHP调用mysql函数的语法: <html> <head> <title>PHP with MySQL</title> </head> <body> <?php $retval = mysql_function(value, [value,...]); if( !$retval ) { die ( "Error: a related error message" ); } // Otherwise MySQL or PHP Statements ?> </body> </html> |