Home > Backend Development > PHP Tutorial > php creates and connects to database

php creates and connects to database

巴扎黑
Release: 2023-03-01 10:46:01
Original
1415 people have browsed it

<?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"数据库选择成功.";
 
}
?>
Copy after login

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template