[root@kvm8 ~]# yum install php-mysql -y
[root@kvm8 ~]# /etc/init.d/httpd restart Stopping httpd: [ OK ] Starting httpd: [ OK ]
mysql_function(value,value,...);
new_link,client_flag 可以不輸入,但一定要提供 server,user,passwd 才能連線。
connection mysql_connect(server,user,passwd,new_link,client_flag);
bool mysql_close ( resource $link_identifier );
[root@kvm8 ~]# cd /var/www/html/
[root@kvm8 html]# vim a.php
<html>
<head>
<title>Connecting MySQL Server</title>
</head>
<body>
<?php
$dbhost = 'localhost:3306';
$dbuser = 'dywang';
$dbpass = '111123qwe';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($conn);
?>
</body>
</html>
[root@dyw219 ~]# curl http://kvm8.deyu.wang/a.php <html> <head> <title>Connecting MySQL Server</title> </head> <body> Could not connect: Access denied for user 'dywang'@'localhost' (using password:
[root@kvm8 html]# vim a.php [root@kvm8 html]# grep pass a.php $dbpass = '123qwe'; $conn = mysql_connect($dbhost, $dbuser, $dbpass);
[root@dyw219 ~]# curl http://kvm8.deyu.wang/a.php <html> <head> <title>Connecting MySQL Server</title> </head> <body> Connected successfully</body> </html>