您的位置:首页 > 编程语言 > PHP开发

PHP---万网虚拟主机数据库(mysql)连接测试

2015-06-16 00:18 831 查看
虚拟主机说明

网站简易搭建
1 上传网页

2 数据库连接测试mysql

3 测试结果

1 虚拟主机说明

  万网虚拟主机信息:

  


2 网站简易搭建

2.1 上传网页

  ftp上传方式,如使用ftp上传软件FileZilla上传测试网页index.php。

  


2.2 数据库连接测试(mysql)

index.php


<!DOCTYPE html>
<html>
<body>

<h3>This is my first PHP!</h3>
<?php
echo "我的第一段 PHP 脚本!";
?>  

<?php
    $mysql_server_name="qdmxxxxxxxxx.my3w.com"; //数据库服务器名称
    $mysql_username="qdmxxxxxxxxx";                // 连接数据库用户名
    $mysql_password="xxxxxxxxx";               // 连接数据库密码
    $mysql_database="qdmxxxxxxxxx_db";         // 数据库的名字

    //连接到数据库
    $conn=mysql_connect($mysql_server_name, $mysql_username,
                        $mysql_password);   
    if(!$conn){
        die('Could not connect: ' . mysql_error());
    }
    //使用数据库
    $db_selected = mysql_select_db($mysql_database, $conn);
    if (!$db_selected)
    {
        die ("Can\'t use qdmxxxxxxxxx_db : " . mysql_error());
    }
    //sql语句
    $strsql="create table tableTest(id int(3) auto_increment not null primary key,name char(8),passwd char(8),date date);";
    //执行sql语句:包括查询、创建等
    if (mysql_query($strsql,$conn)){
        echo "Table tableTest is created";
    }
    else{
        echo "Error creating table: " . mysql_error();
    }
    //关闭数据库
    mysql_close($conn);
?>
</body>
</html>


2.3 测试结果

  index.php执行结果浏览器显示:




  index.php执行结果后台数据库变化结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: