zoukankan      html  css  js  c++  java
  • 自学php 之数据库连接编程

    php连接数据库主要分6部分;

    1)、获取连接

    2)、选择数据库

    3)、设置操作编码

    4)、发送指令

    5)、接受返回结果并处理

    6)、释放资源,关闭连接

     1 <?php
     2 
     3    //获取连接
     4    $conn = mysql_connect('localhost','root','');
     5    if(!$conn){
     6        die('数据库连接失败!'.mysql_error());
     7    }
     8    //选择数据库
     9    mysql_select_db('test');
    10    
    11    //设置操作编码
    12    mysql_query('set names gbk');
    13    
    14    // 发送指令S
    15    $sql="select * from user";
    16    $res=mysql_query($sql,$conn);
    17    //接收返回结果并进行处理
    18    while($row=mysql_fetch_row($res)){
    19    //    echo "<br/> $row[0]--$row[1]--$row[2]--$row[3]--$row[4]";
    20        foreach($row as $key => $val){
    21        echo "--$val";
    22        }
    23        echo '<br>';
    24    }
    25    mysql_free_result($res);
    26 ?>
  • 相关阅读:
    python-杂烩
    24 Python 对象进阶
    23 Python 面向对象
    22 Python 模块与包
    21 Python 异常处理
    20 Python 常用模块
    18 Python 模块引入
    2 Python 基本语法
    1 Python 环境搭建
    3 Python os 文件和目录
  • 原文地址:https://www.cnblogs.com/ouyangduoduo/p/3454690.html
Copyright © 2011-2022 走看看