Can't add sqlite entry using PHP
I have a database with a table. I wrote a simple python program to write to a database as follows.
import sqlite3
import sys
arg = sys.argv
handle= sqlite3.connect('new_test.db')
print "Opened database successfully";
print type(arg[1]), arg[2]
handle.execute("INSERT INTO RECORD (ID,NAME,PROJECT,) \
VALUES ('%s','%s','%s')" %(str(arg[1]), str(arg[2]),str
(arg[3]));
print "after execute"
handle.commit()
print "Records created successfully";
handle.close()
This works fine from the command line python insert.py arg1 arg2 arg3
Now I am doing the same from php code like:
$data=shell_exec("python insert.py $id $name $project").
It doesn't add records to the table. Execution stops aroundhandle.execute
- verified with print statements. What should I change or change?
Is it because of some permissions or do I need to add something? Note: records are not duplicated.
EDIT: Some additional things I've tried that might be helpful:
-
I tried to call the script through PHP, but added static string arguments to the database. It still hasn't passed.
-
I commented
handle.execute()
from the python program, the program now runs to the end. So the problem is with this instruction. - checks environment variables and python modules, they are as expected.
source to share