


PHP WeChat public account development (2) Baidu BAE construction and database use
Jan 03, 2017 am 09:09 AMWeChat is becoming more and more popular. Let’s start learning WeChat public account development today. Before development, if you already know PHP knowledge and HTML/css and other technologies.
1. Apply for a WeChat public account: Address https://mp.weixin.qq.com/
Before registration, you need to take a bust of your ID card and make sure you can see the ID card information clearly. The photos I took with my iPhone 4s can be used. Don’t beautify the photos, just keep them original. It’s not a blind date.
Fill in the relevant information, as long as it is true. It will be reviewed within 7 working days to see if it passes. You will usually know the result in two or three days. If not, just resubmit. You only have 4 chances in total, so be careful.
One person can apply for two official accounts, because both the mobile phone number and the ID card can only be registered twice.
You need to use your email address to register, so apply in advance. Your email address is used for verification and is also your login number.
Individual users can only apply for a subscription account. Governments, enterprises, and media can apply for service accounts. The two types of development are basically the same, but with better services and more functions, we can only choose a subscription account.
After the application is approved, log in and upload an avatar to your account first. Make sure it is the same as the theme of your account. And can be bound to Weibo and so on.
2 Apply for Baidu BAE, which is similar to Sina SAE. The two operations are similar. BAE is used as an example here.
Application address: http://developer.baidu.com/
Just register as a personal type, there is nothing to say, basically no problem.
After passing the application, you can use Baidu BAE. Baidu bae can build websites or serve as a server platform for developing applications, and provides many interfaces.
Find the management center - "Cloud Platform Management -" Quickly create an application in the upper right corner:
Fill in the application name, select mobile application as the access method, and confirm.
When the application is generated, you can set up the cloud environment for the application, that is, which language to develop it in. Here, choose php.
Get familiar with the backend, which provides many functions. Details will be introduced later, this is just preliminary knowledge!
The above is mainly some preparatory knowledge, and then there is the preparatory knowledge. You can develop WeChat without using a database, but if you want to build some query applications, you may use database operations, so this section mainly involves Baidu BAE The above database table creation, inserting data, modifying data, deleting data, deleting tables, and transaction operations.
Before development, go to bae to create an application, and then add the database MySQL. A database name will be automatically generated, which is a string.
Mysqli is used here for testing, which is similar to MySQL.
$dbname = "tIXZeAfkXSSgYzKuMwGZ";//百度bae數(shù)據(jù)庫 這就是生成的數(shù)據(jù)庫,要替換成自己的 /*從環(huán)境變量里取出數(shù)據(jù)庫連接需要的參數(shù)*/ $host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP'); $port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'); $user = getenv('HTTP_BAE_ENV_AK'); $pwd = getenv('HTTP_BAE_ENV_SK'); $db= new mysqli($host,$user,$pwd,$dbname,$port); if(mysqli_connect_errno()){ die("coonet error").mysqli_connect_errno(); }else{ echo 'ok'; } $db->query("set names utf8");
This is the Baidu bae database connection, and then you can use mysqli related database methods to operate.
1.Create table
$sql = "create table if not exists t_mysql( id int(10) primary key AUTO_INCREMENT, no int(10), name VARCHAR(255))"; $result = $db->query($sql); if($result){ echo "創(chuàng)建表成功"; }
2.Insert
$sql ="insert into t_mysql(id,no,name) values(null,1,'你好')"; $result = $db->query($sql); if($result){ echo '插入成功'; }
3.Modify
$sql ="update t_mysql set name='重活' where id=1"; $result = $db->query($sql); if($db->affected_rows>0 && $result){ echo '修改成功'; }
4.Delete
$sql ="delete from t_mysql where id=4"; $result = $db->query($sql); if($result && $db->affected_rows>0){ echo '刪除成功'; }
5.Query
$sql = "select * from t_mysql"; $result = $db->query($sql); if($result){ $row = $result->fetch_row(); //索引數(shù)組 $r[0] print_r($row); }
6. Delete table
$sql = "drop table if exists t_mysql"; $result = $db->query($sql); if($result){ echo "刪除表成功"; }
7. Transaction (note that only the innoDB engine supports myisam and does not support transactions)
$db->autocommit(FALSE); $result1 = $db->query("insert into t_mysql values(null,3,'2333')"); $result2 = $db->query("insert into t_mysql values(null,5,'44433')"); if($result1 && $result2){ $db->commit(); echo 'ok'; }else{ $db->rollback(); }
The above is the basic operation of BAE, in fact, it is general PHP Operating the database is enough to build a general WeChat application on it.
File download http://xiazai.jb51.net/201612/yuanma/baemysqli(jb51.net).rar
Outside article
mysql database connection code
<?php $dbname = "tIXZeAfkXSSgYzKuMwGZ";//百度bae數(shù)據(jù)庫 /*從環(huán)境變量里取出數(shù)據(jù)庫連接需要的參數(shù)*/ $host = getenv('HTTP_BAE_ENV_ADDR_SQL_IP'); $port = getenv('HTTP_BAE_ENV_ADDR_SQL_PORT'); $user = getenv('HTTP_BAE_ENV_AK'); $pwd = getenv('HTTP_BAE_ENV_SK'); /*接著調(diào)用mysql_connect()連接服務(wù)器*/ $link = @mysql_connect("{$host}:{$port}",$user,$pwd,true); if(!$link) { die("Connect Server Failed: " . mysql_error()); } /*連接成功后立即調(diào)用mysql_select_db()選中需要連接的數(shù)據(jù)庫*/ if(!mysql_select_db($dbname,$link)) { die("Select Database Failed: " . mysql_error($link)); } else{ echo 'ok'; } mysql_query("set names utf8");//設(shè)置編碼utf8 ?>
The above is the content of PHP WeChat public account development (2) Baidu BAE construction and database use. For more related content, please pay attention to the PHP Chinese website (m.miracleart.cn)!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Scrapy implements article crawling and analysis of WeChat public accounts. WeChat is a popular social media application in recent years, and the public accounts operated in it also play a very important role. As we all know, WeChat public accounts are an ocean of information and knowledge, because each public account can publish articles, graphic messages and other information. This information can be widely used in many fields, such as media reports, academic research, etc. So, this article will introduce how to use the Scrapy framework to crawl and analyze WeChat public account articles. Scr

The difference between WeChat public account authentication and non-authentication lies in the authentication logo, function permissions, push frequency, interface permissions and user trust. Detailed introduction: 1. Certification logo. Certified public accounts will obtain the official certification logo, which is the blue V logo. This logo can increase the credibility and authority of the public account and make it easier for users to identify the real official public account; 2. Function permissions. Certified public accounts have more functions and permissions than uncertified public accounts. For example, certified public accounts can apply to activate the WeChat payment function to achieve online payment and commercial operations, etc.

Python is an elegant programming language with powerful data processing and web crawling capabilities. In this digital era, the Internet is filled with a large amount of data, and crawlers have become an important means of obtaining data. Therefore, Python crawlers are widely used in data analysis and mining. In this article, we will introduce how to use Python crawler to obtain WeChat public account article information. WeChat official account is a popular social media platform for publishing articles online and is an important tool for promotion and marketing of many companies and self-media.

In today's Internet era, WeChat official accounts have become an important marketing channel for more and more companies. If you want your WeChat official account to implement more functions, you often need to write corresponding interfaces. This article will use PHP language as an example to introduce how to build a WeChat public account API interface. 1. Preparation Before writing the WeChat public account API interface, the developer needs to have a WeChat public account and apply for developer interface permissions in the WeChat public platform. After the application is successful, you can obtain the relevant developer AppID and AppSe

How to use Laravel to develop an online ordering system based on WeChat official accounts. With the widespread use of WeChat official accounts, more and more companies are beginning to use them as an important channel for online marketing. In the catering industry, developing an online ordering system based on WeChat public accounts can improve the efficiency and sales of enterprises. This article will introduce how to use the Laravel framework to develop such a system and provide specific code examples. Project preparation First, you need to ensure that the Laravel framework has been installed in the local environment. OK

The public account can not only post one article per day, but can publish up to eight articles at a time. How to publish multiple articles: 1. Click "Material Management" on the left, and then click "New Graphic and Text Material" to start editing. First article; 2. After editing the first article, click the + sign under the first article on the left and click "Graphic Message" to edit the second article; 3. After finishing multiple images and text, click " Save and send in bulk" to complete the publishing of multiple articles.

With the popularity of the Internet and the widespread use of mobile devices, WeChat official accounts have become an indispensable part of corporate marketing. Through WeChat public accounts, companies can easily interact with users, promote products and services, and increase brand awareness. In order to better develop WeChat public account applications, more and more developers and companies choose to use Go language to build WeChat public account applications. Go language is a programming language developed by Google. Its syntax is concise and suitable for building high-performance, high-concurrency real-time applications. In terms of ease of use and

According to news from this website on August 1, the WeChat Public Platform Operations Center issued an article today saying that the platform found that some articles published by operators contain feudal superstitions and use religion, feng shui, fortune and other gimmicks to make money or gain attention. Such content is very likely Causing misleading or property damage to users. WeChat will conduct continuous inspections, and once any illegal content is discovered, corresponding actions will be taken according to the specific degree of the violation. The violation cases attached to this site are as follows: publishing superstition-related titles, using intimidation, inducement and other tones to exaggerate the harm or negative impact of a certain behavior. ▲Picture source WeChat Public Platform Operation Center, the same article below provides services with feudal superstitions such as fortune telling, fortune telling, and divination, and includes paid items, such as the sale of transshipment and disaster relief products. Improperly collecting users’ personal privacy information in the name of providing relevant services
