码迷,mamicode.com
首页 > 数据库 > 详细

封装连接数据库

时间:2016-11-28 07:53:55      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:失败   pass   return   use   bsp   连接数据库   roo   res   sel   

$host =‘localhost‘;
        $root = ‘root‘;
        $dbpass  = ‘‘;
        $db = ‘zhuce‘;
        $f = mysql_connect($host,$root,$dbpass);
        if(!$f){
            echo ‘数据库连接失败‘;
            die;
        }
        $f=mysql_query("use $db");
            if(!$f){
                echo ‘数据库选择失败‘;
            }
        mysql_query("set names utf8");

        function my_select($sel){ //查询数据
            $res =  mysql_query($sel);
            $result = array();
            while($se=mysql_fetch_assoc($res)){
                    $result=$se;
            }
            return $result;
        }
        function my_insert($sql){  //插入数据
                $insert=mysql_query($sql);    
        }

封装连接数据库

标签:失败   pass   return   use   bsp   连接数据库   roo   res   sel   

原文地址:http://www.cnblogs.com/phpindex/p/6107824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!