本文介绍了PHP无法通过python连接到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个PHP来执行一个像这样连接到mysql的python脚本

Im writing a PHP to exec a python script which connects to mysql like this

<?php
    echo shell_exec('python doSmt.py 2>&1');
</body></html>")
?>

在Python脚本中:

in Python script:

# -*- coding: utf-8 -*-
import mysql.connector

并得到此错误

请帮助

更新:我尝试从netbeans检查安装在php Web服务器上的软件包

UPDATE:I tried checking packages installed on php web server from netbeans

# -*- coding: utf-8 -*-
import pkg_resources
installed_packages = pkg_resources.working_set
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
     for i in installed_packages])
print(installed_packages_list)

得到了

没有与mysql相关的软件包.我认为这是问题所在.但是如何解决呢?

There's no package relating to mysql. I think this is the problem. But how to fix this?

推荐答案

确保doSmt.py文件的第一行中包含以下文本:

make sure you have the following text in the first line of doSmt.py file:

#!/usr/bin/env python

这篇关于PHP无法通过python连接到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 11:23