<?php
function database_ini()
{
$dbname = "数据库名称";
// 连接数据库需要的参数
$host = "localhost";
$user = "使用者名字";
$pwd = "密码";
// 接着调用mysql_connect()连接服务器
$link = mysql_connect($host,$user,$pwd);
if(!$link) {
die("Connect Server Failed: " . mysql_error());
}
// 连接成功后立即调用mysql_select_db()选中需要连接的数据库
if(!mysql_select_db($dbname,$link)) {
die("Select Database Failed: " . mysql_error($link));
}
mysql_query("set names utf8");
return $link;
}
// 查询数据
// 参数:sql语句
function database_query($sql, $link)
{
$ret = mysql_query($sql, $link);
if($ret == false){
die("Select Failed: " . mysql_error($link));
}
// 以数组形式解析返回数据(数据没有重复的情况)
// $rs = mysql_fetch_array($ret);
return $ret;
}
// 向数据库插入数据
function data_insert($sqls,$link)
{
// $sql = sprintf("INSERT INTO `Leaguer` (`Tel` ,`Mail`) VALUES ('%d', '%s')", $tel, $mail);%后面的是反单引号
//$sql = "insert into Auto_Answer(Question, Answer) values('hello and hi', '您好')";
$ret = mysql_query($sqls, $link);
if ($ret == false) {
die("Insert Failed: " . mysql_error($link));
} else {
//echo "Insert Succeed";
}
}
?>
<?php
$link =database_ini();
//$sql = "insert into access_token(access_token) values('aaa')";
$sql = "select *from access_token";
$data = database_query($sql,$link);
$i = 0;
$cc ='access_token';
while($row = mysql_fetch_array($data)){
$arr[$i][$cc] = $row['Acess'];
$arr[$i]['createtime'] = $$row['createtime'];
$i++;
}
// while ($property = mysql_fetch_field($data)) {
// // echo "Field name: " . $property->Acess . "<br />";
// }
mysql_close($link);
for ($j=0; $j < $i-1; $j++) {
echo $arr[$j]['access_token'];
echo "</br>";
}
?>
function database_ini()
{
$dbname = "数据库名称";
// 连接数据库需要的参数
$host = "localhost";
$user = "使用者名字";
$pwd = "密码";
// 接着调用mysql_connect()连接服务器
$link = mysql_connect($host,$user,$pwd);
if(!$link) {
die("Connect Server Failed: " . mysql_error());
}
// 连接成功后立即调用mysql_select_db()选中需要连接的数据库
if(!mysql_select_db($dbname,$link)) {
die("Select Database Failed: " . mysql_error($link));
}
mysql_query("set names utf8");
return $link;
}
// 查询数据
// 参数:sql语句
function database_query($sql, $link)
{
$ret = mysql_query($sql, $link);
if($ret == false){
die("Select Failed: " . mysql_error($link));
}
// 以数组形式解析返回数据(数据没有重复的情况)
// $rs = mysql_fetch_array($ret);
return $ret;
}
// 向数据库插入数据
function data_insert($sqls,$link)
{
// $sql = sprintf("INSERT INTO `Leaguer` (`Tel` ,`Mail`) VALUES ('%d', '%s')", $tel, $mail);%后面的是反单引号
//$sql = "insert into Auto_Answer(Question, Answer) values('hello and hi', '您好')";
$ret = mysql_query($sqls, $link);
if ($ret == false) {
die("Insert Failed: " . mysql_error($link));
} else {
//echo "Insert Succeed";
}
}
?>
<?php
$link =database_ini();
//$sql = "insert into access_token(access_token) values('aaa')";
$sql = "select *from access_token";
$data = database_query($sql,$link);
$i = 0;
$cc ='access_token';
while($row = mysql_fetch_array($data)){
$arr[$i][$cc] = $row['Acess'];
$arr[$i]['createtime'] = $$row['createtime'];
$i++;
}
// while ($property = mysql_fetch_field($data)) {
// // echo "Field name: " . $property->Acess . "<br />";
// }
mysql_close($link);
for ($j=0; $j < $i-1; $j++) {
echo $arr[$j]['access_token'];
echo "</br>";
}
?>