Home > Backend Development > PHP Tutorial > How to connect multiple databases in php at the same time_PHP tutorial

How to connect multiple databases in php at the same time_PHP tutorial

WBOY
Release: 2016-07-13 17:18:41
Original
1229 people have browsed it

The following is a function that can ensure the connection of different tables in multiple databases. You can save it. It is more practical and useful after testing.

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;
		}
	}
Copy after login


The default is query operation, you can modify this code according to your own requirements! , which is the code under the action of the $oper operator

For example, if I now want to query the shop data table under the database named test, and the data with IDs between 10 and 12, then I can call it like the following

mysql_oper('select','test','shop','id>=10 and id



www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/621641.htmlTechArticleThe following is a function that can ensure the connection of different tables in multiple databases. You can save it and it is more practical. , tested and found to be useful. function mysql_oper($oper,$db,$tabl...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template