phpstudy连接数据库代码
phpstudy数据库创建好之后,
默认用户名:root
默认密码:root
主机名:localhost
端口:3306
demo:
<?php $hostName = "localhost"; $usrName = "root"; $passWord = "root"; $port = "3306"; $dbname = "flyingman"; $content = mysqli_connect($hostName,$usrName,$passWord,$dbname,$port); mysqli_set_charset($content,'utf-8'); if(!$content){ die("connect failed!:".mysqli_connect_error()); }else{ echo "connect success!"; } mysqli_close($content);
本地浏览器打开中文乱码,上传到服务器又正常解决方案:在PHP文件开头添加下面这句设置字符集
header("content-type:text/html;charset=utf-8");
推荐教程:phpStudy极速入门视频教程
以上就是phpstudy连接数据库代码的详细内容,更多请关注其它相关文章!