简体   繁体   中英

call python script from php that connects to MySQL

I am able to easily call a python script from php using system() , although there are several options. They all work fine, except they all fail. Through trial and error I have narrowed it down to it failing on

import MySQLdb

I am not too familiar with php, but I am using it in a pinch. I understand while there could be reasons why such a restriction would be in place, but this will be on a local server, used in house, and the information in the mysql db is backed up and not to critical. Meaning such a restriction can be reasonably ignored.

But how to allow php to call a python script that imports mysql? I am on a Linux machine (centOs) if that is relevant.

The Apache user (www-data in your case) has a somewhat restricted environment. Check where the Python MySQLdb package is installed and edit the Apache user's env (cf Apache manual and your distrib's one about this) so it has a usable Python environment with the right PYTHONPATH etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM