zoukankan      html  css  js  c++  java
  • php如何同时连接多个数据库

    下面是一个函数能够保证连接多个数据库的下不同的表的函数,可以收藏一下,比较实用,测试过是有用的。

    function mysql_oper($oper,$db,$table,$where='1',$limit='10'){
    	 	$conn=mysql_connect('localhost','like','admin',true) or mysql_error();
    	 	mysql_select_db($db,$conn);
    	 	mysql_query("set names utf8");//必须和表单数据字符保持一致
    		if($oper=='select'){
    		 	$query="select * from `$table` where ".$where." limit ".$limit;
    			$res=mysql_query($query,$conn) or die("获取数据失败");
    			$arr=array();
    			while($row=mysql_fetch_row($res)){
    				$arr[]=$row;
    			}
    			mysql_close($conn);
    			return $arr;
    		}
    	}


    默认是查询操作,你可以根据你自己的要求修改这段代码!,就是那个$oper操作符作用下的代码

    例如我现在要查询名为test的数据库下的shop数据表,并且id在10到12的数据,那么我就像下面这样去调用就可以了

    mysql_oper('select','test','shop','id>=10 and id<=12');



  • 相关阅读:
    ftp的基本工作原理
    ubuntu自带输入法ibus 无法按数字键取词
    C语言教程
    【数据结构】---线性表
    python搭建opencv
    第六届Code+程序设计网络挑战赛
    整除分块
    ac自动机
    算法梳理 (CSP 2019
    lougu main page
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3458859.html
Copyright © 2011-2022 走看看