Home  >  Article  >  Backend Development  >  php creates and connects to database

php creates and connects to database

巴扎黑
巴扎黑Original
2016-11-30 09:48:281340browse

<?php 
//首先保证本机创建了php环境,并建立了数据库,"localhost"是服务器地址;","root",""是登陆的用户名和密码,"@"的意思是屏蔽报错;
$link=@mysql_connect("localhost","root","");
if(!$link){die("error");}
/* die()函数的意思是将括号里的字串送到浏览器并中断PHP程式 (Script)。括号里的参数为欲送出的字串。 */
//选择服务器上的名为test的数据库;
$db_selected=mysql_select_db("test",$link);
//如果链接成功,打印出数据;
if($db_selected){
 echo"数据库选择成功.";
 
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn