Home  >  Article  >  php教程  >  PHP连接数据库

PHP连接数据库

PHP中文网
PHP中文网Original
2016-05-25 16:58:111381browse

跳至

<?php
    $mysql_server_name="localhost"; //数据库服务器名称
    $mysql_username="root"; // 连接数据库用户名
    $mysql_password="123456"; // 连接数据库密码
    $mysql_database="user"; // 数据库的名字
    
    // 连接到数据库
    $conn=mysql_connect($mysql_server_name, $mysql_username,
                        $mysql_password);
                        
     // 从表中提取信息的sql语句
    $strsql="SELECT * FROM `student`";
    // 执行sql查询
    $result=mysql_db_query($mysql_database, $strsql, $conn);
    // 获取查询结果
    $row=mysql_fetch_row($result);
    
     
    echo &#39;&#39;;
    echo &#39;&#39;;

    // 显示字段名称
    echo "";
    for ($i=0; $i<mysql_num_fields($result); $i++)
    {
      echo &#39;&#39;.
      mysql_field_name($result, $i);
      echo "";
    }
    echo "";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "";
      for ($i=0; $i

                   

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