I have a python script which takes csv as an input and insert its data to Database. and I am calling this script from a php script where I am generating this CSV. If I call python script from terminal and pass csv to it, it works perfectly but if I call it from php using
exec('python bulk_metadata_ingest_dev.py '. $metadataCSV);
It throws a mysql error while inserting to a table.
_mysql_exceptions.ProgrammingError: (1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \'text to insert""\' at line 1')
Query which throwing this error :
cursor = db.query("insert into test_table(asset_type, attribute_id, asset_title, is_publishable, owner) values(\""+str(mediaAssetTypeDict[sample_content.media_type.lower()])+"\", \""+str(attributeId)+"\", \""+str(assetTitle)+"\", \""+str(publishAssets)+"\", \""+str(sample_content.content_owner)+"\" )")
In python I don't know how to handle this problem. Thanks in advance
cursor = db.query("insert into test_table(asset_type, attribute_id, asset_title, is_publishable, owner) values('"+str(mediaAssetTypeDict[sample_content.media_type.lower()])+"', '"+str(attributeId)+"', '"+str(assetTitle)+"', '"+str(publishAssets)+"', '"+str(sample_content.content_owner)+"')")? I know databases, that do not like double quotes around string literals ...