php wampp 访问数据库

时间:2024-06-18 10:37:32

//获取用户信息
private function UlikeGetUserInfo($Wechat,$data)
{
$this->logger("到达UlikeFunction.inc.php中的UlikeGetUserInfo");
$access_token=$this->get_token();
$openid=$data['FromUserName'];
$this->logger("FromUserName是:".$data['FromUserName']);
$url="https://api.weixin.qq.com/cgi-bin/user/info?access_token=$access_token&openid=$openid&lang=zh_CN";
$this->logger("url是:".$url);
$jsonInformation=$this->http_curl($url);
$this->logger($jsonInformation);
$UserarrInformation=json_decode($jsonInformation,true);
$this->logger("UserarrInformation是:".$UserarrInformation);
$this->insertUserInformation($UserarrInformation,$Wechat);

}
//进行数据库插值
private function insertUserInformation($User,$Wechat)
{

$this->logger("到达了数据库进行插值处理!");
$this->logger($User['openid']);
$link=mysql_connect("127.0.0.1","root","");
if($link)
{
$this->logger("数据库连接成功");
}else{
$this->logger("数据库连接失败");
}
mysql_select_db("weixin", $link);
$sql="insert into ulikeuser values('{$User["openid"]}','{$User["nickname"]}','{$User["sex"]}','{$User["city"]}','{$User["province"]}','{$User["headimgurl"]}','".time()."')";
// $sql="insert into Info values('lang','21','男生')";
//$sql2="select sex from Info where name='lilang1'";
//mysql_query($sql,$link);
mysql_query("set names 'utf8'");//不加入会出现乱码
$result=mysql_query($sql,$link);
if($result)
{$this->logger("您已经执行数据库文件!".$result);}
else
{
$this->logger("您的数据没有插入成功!");
}
mysql_close($link);

}