0

I am trying to query athena using php. My code is as below which works.

PHP

<?php
$sql2Py = "'SELECT address,order,status from myDB.order;'";
$output = shell_exec("python3 pythonScript.py $sql2Py");
echo "my result-" . $output;
?>

pythonScript.py

#!/usr/bin/env python
import os
import sys
from pyathena import connect
import pandas

sql = str(sys.argv[1])
orders = pandas.read_sql(sql,conn) 
print (orders)

How do I escape the quotes while adding a string to the query? I tried using backslash like below but this does not work.

$sql2Py = "'SELECT address,order,status from myDB.order where status <> \'Completed\';'";
Santosh Pillai
  • 1,311
  • 1
  • 20
  • 31

0 Answers0