<?php
return array (
'default' => array (
'hostname' => '127.0.0.1',
'database' => 'csshop',
'username' => 'root',
'password' => 'root',
'tablepre' => 'bz_',
'charset' => 'utf8',
'type' => 'mysql',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
);
文件 database.php
**************************************************************
$mysql_user=include('../database.php');
$username=$mysql_user['default']['username'];
$password=$mysql_user['default']['password'];
$tablepre=$mysql_user['default']['tablepre'];
$database=$mysql_user['default']['database'];
$con = mysqli_connect($mysql_user['default']['hostname'],$username,$password)or die("连接服务器失败");
mysqli_select_db($con,$database) or die("数据库连接失败");
<?php
function select ($con, $table, $where , $field, $order = ' id ASC ' ,$all = '' ,$tablepre = '') {
if( $all ){
$sql = ' SELECT ' .$field. ' FROM '.$tablepre.''.$table.' where ' .$where .' order by "' .$order. '"';
}else{
$sql = ' SELECT ' .$field. ' FROM '.$tablepre.''.$table.' where ' .$where. ' limit 1';
}
$result2= mysqli_query ( $con, $sql);
if (!$result2) {
printf("Error: %s\n", mysqli_error ( $con));
exit ();
}
if( $all ){
$row = $result2->num_rows;
while ($row> 0) {
$data[] = mysqli_fetch_array ($result2);
$row -=1;
}
}else{
$data = mysqli_fetch_array ($result2);
}
return $data;
}
function closemysql($con){
mysqli_close($con);
}