search
Homephp教程php手册PHP与Mysql的连接

呼,搞了足足两天零12个小时05分17秒,恍然大悟,原来我把数据库的名字写错了,导致这两天零12个小05分17秒的时间,都在迷惘中度过,不过现在算是解决了,所来特来发下心得体会。 忠告:写程序切记马虎,不细仔,真是写程序的大忌中的大忌。所以以后写代码务

呼,搞了足足两天零12个小时05分17秒,恍然大悟,原来我把数据库的名字写错了,导致这两天零12个小05分17秒的时间,都在迷惘中度过,不过现在算是解决了,所来特来发下心得体会。

忠告:写程序切记马虎,不细仔,真是写程序的大忌中的大忌。所以以后写代码务必:细心仔细不骄不燥,才能写出来好代码来,避免迷惘。。

 

 

 繁写:

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

';

    // 显示字段名称
    echo "
";
    for ($i=0; $i    {
      echo '
";
    }
    echo "
";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "
";
      for ($i=0; $i      {
        echo '
';
      }
      echo "
";
    }
   
    echo "
'.
      mysql_field_name($result, $i);
      echo "
';
        echo $row[$i];
        echo '
";
    echo "
";
    // 释放资源
    mysql_free_result($result);
    // 关闭连接
    mysql_close($conn);  
?>

 

简写:

 $conn=mysql_connect("localhost", "root", "password");            
 $result=mysql_db_query("Database", "SELECT * FROM `info`", $conn);
    // 获取查询结果
     $row=mysql_fetch_row($result);
    
     
    echo '';
    echo '

';

    // 显示字段名称
    echo "
";
    for ($i=0; $i    {
      echo '
";
    }
    echo "
";
    // 定位到第一条记录
    mysql_data_seek($result, 0);
    // 循环取出记录
    while ($row=mysql_fetch_row($result))
    {
      echo "
";
      for ($i=0; $i      {
        echo '
';
      }
      echo "
";
    }
   
    echo "
'.
      mysql_field_name($result, $i);
      echo "
';
        echo $row[$i];
        echo '
";
    echo "
";
    // 释放资源
    mysql_free_result($result);
    // 关闭连接
    mysql_close($conn);  
?>

 

 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools