Instance:
First build the MySQL configuration file dbconfig.php
<? PHP $phpexcel=array( "host" = ' localhost ',//127.0.0.1 " Username "+" root ",// username " password "=" 123 ",// password " Database "= =" Phpexcel ",// Data base name " charset "=" UTF8 "// code );? >
View Code
PHP operation MySQL File
<?PHPrequire dirname(__file__)." /dbconfig.php ";//introducing a configuration file classdb//MySQL Operation class Public $conn=NULL;//Initialize Public function_construct ($config){//connecting to a database $this->conn=mysql_connect($config["Host"],$config["username"],$config["Passwork"]or die(Mysql_error));//connecting to a databasemysql_select_db($config["Database"],$this->conn) or die(Mysql_error));//Select Databasemysql_query("Set Names",$config["CharSet"]or die(Mysql_error());//set MySQL code }/** * * query MySQL result set based on incoming SQL statement **/ Public functionGetResult ($sql){$resource=mysql_query($sql,$this->conn) or die(Mysql_error());//Querying SQL statements$res=Array(); while(($row=Mysql_fetch_assoc($resource))!=false){$res[]=$row;}return $res;}?>View Code
reading data and outputting local files
<?php
?>
MySQL configuration file Authoring