您的位置 首页 php

微信小程序连接Mysql数据库步骤

刚开始学小程序没多久,这么一个简单的过程整了一个礼拜,关键是没人指导啊啊啊啊啊……心累,翻阅了n个书籍,查看了m个网站,亲测可以正常连接。现在终于明白了学习效率:培训班>看视频>自学。好啦,不多说了,进入正题!

1、数据库插入数据。 Mysql 数据库我没有放在本地,是放在远程服务器的,其实最终就是IP地址的问题。首先数据库里插入四条语句,如下图所示,

微信小程序连接Mysql数据库步骤

2、 tomcat 部署php。过程步骤如下,

1) 首先下载php程序,是一个zip的压缩包。如下图所示,

微信小程序连接Mysql数据库步骤

2) 将下载的php压缩包解压到tomcat的安装路径下,并重命名为php,如下图所示,

微信小程序连接Mysql数据库步骤

3) 查看电脑中是否已安装php的方法:计算机-属性-高级设置中点击“环境变量”,添加PATH环境变量,可以添加Admin环境变量,也可以添加系统环境变量,看个人需求,将php解压路径添加到PATH中。之后打开cmd,输入php -v或 php –version,如下图所示,

微信小程序连接Mysql数据库步骤

微信小程序连接Mysql数据库步骤

4)将php路径下的php. ini -development 复制,将副本改名php.ini,之后用记事本打开php.ini。(可以看出;为其注释符)修改其中两项设置:

①去掉 ext ension_dir = “ext”前面的 ; ”, 并且将extension_dir = “ext”修改为绝对路径,

②cgi.force_redirect修改为0,并去掉前面的 ; ”, 即 cgi.force_redirect = 0

如下图,

微信小程序连接Mysql数据库步骤

5)打开tomcat的conf文件夹。

选择context.xml文件,在<Context >加上属性privileged=”true”,如下图所示,

微信小程序连接Mysql数据库步骤

6)仍在tomcat的conf文件夹中。

修改web.xml文件,在<web-app>中加入如下的< servlet >

微信小程序连接Mysql数据库步骤

插入代码如下:

<servlet>

<servlet-name>php</servlet-name>

<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>

<init-param>

<param-name>clientInputTimeout</param-name>

<param-value>200</param-value>

</init-param>

<init-param>

<param-name>debug</param-name>

<param-value>0</param-value>

</init-param>

<init-param>

<param-name>executable</param-name>

<param-value>D:tomcatphpphp-cgi.exe</param-value>

</init-param>

<init-param>

<param-name>passShellEnvironment</param-name>

<param-value>true</param-value>

</init-param>

<init-param>

<param-name>cgiPathPrefix</param-name>

<param-value>WEB-INF/phpbin</param-value>

</init-param>

<load-on-startup>5</load-on-startup>

</servlet>

7) 在<web-app>中加入如下的<servlet-mapping>,表示php 脚本 路径。

微信小程序连接Mysql数据库步骤

代码如下:

<servlet-mapping>

<servlet-name>php</servlet-name>

<url-pattern>/phpbin/*</url-pattern>

</servlet-mapping>

8) 新建一个api.php文件,文件内容如下。

在webappsROOTWEB-INF下新建一个phpbin的文件夹,并将api.php放置其中,如下图,

微信小程序连接Mysql数据库步骤

$sql=”select * from persons”;

$res=$link->query($sql);

$data=$res->fetch_all();

echo json_encode($data);

?>

api.php脚本代码如下(新建txt文件,修改后缀名为php即可):

<?php

$link = new mysqli(‘10.103.20.54′,’root’,’abcdefg’,’test’);

$link->set_charset(“utf8”);

if($link->connect_error){

die(“连接失败:”.$link->connect_error);

}

9)打开tomcat(在bin文件夹下,双击startup.bat,苹果系统双击startup.sh文件即可打开tomcat服务)。

打开浏览器,输入localhost:8080/phpbin/index.php,看到如下页面,表明配置php配置成功!

微信小程序连接Mysql数据库步骤

3、 微信小程序 端。

1)新建一个项目,在index.wxml里输入:

<view wx:for=”{{data}}”>

{{item}}

</view>

2)index.js里输入:

onLoad: function () {

let that = this;

wx. request ({

url: ‘#39; ,

method: ‘GET’ ,

header: {

‘Content-Type’ : ‘application/json’ ,

},

data: {

},

success: function (res) {

console.log(res)

that.setData({

data:res.data,

})

},

fail: function () {

console.log( “请求数据失败” );

},

complete: function () {

}

})

}

3)预览一下,成功!

微信小程序连接Mysql数据库步骤

文章来源:智云一二三科技

文章标题:微信小程序连接Mysql数据库步骤

文章地址:https://www.zhihuclub.com/79006.shtml

关于作者: 智云科技

热门文章

评论已关闭

38条评论

  1. Rugiet boasts an impressive absorption rate, and the lozenges even taste good, but BlueChew s chewables are stable at room temperature and can travel more easily, earning them practicality points However, Tadalafil doesn t trigger an erection on its own and sexual stimulation is still required

  2. State the purpose of this phenomenon is attributed ta persistent processus vaginalis, which is now well established Table 1 Gonadotoxic Drugs Group Definite gonadotoxicity Alkylating agents Cyclophosphamide 5 Chlorambucil Mustine Melphalan Busulfan 9 Carmustine 10 Lomustine 10 Antimetabolites Cytarabine Vinca alkaloids Vinblastine 11 Others Procarbazine Cisplatin 12 Chapter 20 The Effects of testosterone deficiency generic american cheap levitra in sickle cell anemia

  3. 1 x 10 6 mL, respectively before treatment with CC. Swierkowski-Blanchard N, Boitrelle F, Alter L, et al.

  4. Rachel uses her own experiences with infertility to write compassionate, practical, and supportive articles.

  5. go to Immortal Venerable Vast Vast Tianji faction no longer has its former glory, and will never return to its former peak, we still have to serve our sect.

  6. I don t believe that it is mandatory on the basis of these data to use castration in combination with tamoxifen, but it is my opinion that the data provide sound evidence for this combined treatment as a reasonable choice for these women, Dr Michael Rutlin, PhD Conceptualization Equal; Data curation Equal; Formal analysis Lead; Investigation Lead; Writing original draft Lead; Writing review editing Equal

  7. He was treated effectively with high doses of LH RH 200 micrograms day for 3 days, and normal function progressively returned

  8. We came near it and we found that it was a beast called Al Anbar Moreover, the production and secretion of a STAT3 activator, leukemia suppressive factor, was activated in RES treated cells

  9. If you have any problems with balance, feel unsteady, or have feelings of dizziness, you should not exercise with low platelet counts Characterization of the UFH 001 cells is described in two recent publications 71, 72

  10. Similar to TAM, the E2 treatment had no significant effect on the mean ER О±46 expression Ој AUC_neg 4

  11. The Dutch Pharmacogenetics Working Group Guideline edited the same recommendation for codeine, tramadol and oxycodone 28

  12. Tocilizumab, a humanized monoclonal antibody to the interleukin 6 receptor, has been used in patients with acute kidney injury resulting from cytokine release syndrome after chimeric antigen receptor T cell therapy Koester SK, Maenpaa JU, Wiebe VJ, Baker WJ, Wurz GT, Seymour RC, Koehler RE, DeGregorio MW

  13. He repeats the message so that the hard of hearing listener can lip read and speak his answer directly into the telephone

  14. To be on the safe side, avoid taking cranberry extract products or drinking a lot of cranberry juice if you have a history of kidney stones This means that a cracked or broken tooth can t knit itself together, and enamel lost to decay won t grow back

  15. This action results in increased pH value of stomach contents, thus providing relief of hyperacidity symptoms

  16. Transient Acantholytic Dermatosis are generally observed in middle aged and older men onset age is between 40 and 50 years The condition is rare in children and younger individuals Both males and females are affected, although more men are affected than women men women ratio is around 2 1 Worldwide, there is no racial or ethnic preference observed

  17. The following topics represent the main methods used in the production of different types of nanomaterials explored in medicine

  18. In terms of pharmacologic options, bupropion has been tested in a very small open label trial of sexual function in breast cancer patients Example 21 Adverse Events AEs

  19. Rabinerson D, Avrech O, Kaplan B, Braslavsky D, Goldman GA, Neri A 1996 Endometrioma of the vagina in menopause

  20. How to tell this drug is working For high blood pressure Your blood pressure should go down

  21. Blood work done, found I have hyperthyroidism and took medicine now badly convert as hypothyroidism so far off the medicine till 1 month 2

  22. Tell your doctor right away if you have any serious side effects, including signs of kidney problems such as change in the amount of urine, symptoms of heart failure such as swelling ankles feet, unusual tiredness, unusual sudden weight gain

  23. Its the muscle inbetween your anus and scrotum sack and it tenses and contracts during orgasm or proir

  24. Anker SD, Doehner W, Rauchhaus M, Sharma R, Francis D, Knosalla C, et al 2003 Uric acid and survival in chronic heart failure Validation and application in metabolic, functional, and hemodynamic staging

网站地图