Receiving xml file via hosted php tropo script - php

How do you place a phone call using tropo by sending xml to a tropo hosted script?
This php script is supposed to use curl to post xml to another php script (hosted # tropo). The tropo-hosted script is then supposed to use the xml to place a phone call. In the below example, the tropo debugger is receiving the correct information, since messages like this show up in the debugger:
customerName:Kent is added into the context of app instance : ApplicationInstance[http://hosting.tropo.com/107029/www/ExternalPhoneHelper.php , sas_2-14-sm25ogjh4vlab5tropo]
Here's the curl php script that sends the xml data to tropo:
$token = "mytoken";//removed actual token
$url = PhoneHelper::$TROPO_URL;
$xml = "
<session>
<token>" . $token . "</token>
<var name=\"action\" value=\"create\"/>
<var name=\"customerName\" value=\"Kent\" />
<var name=\"numberToDial\" value=\"##########\" />
<var name=\"msg\" value=\"XML Test\" />
</session>";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
echo curl_error($ch);
echo $output;
curl_close($ch);
The receiving script is empty:
<?php
?>
If the call() and say() methods should be used, how would I reference the posted xml to get numberToDial and msg?
Here is the debugger log:
|-----------------------------------------------------------------------|
|00000|00-1|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=-1 sessionNumber=-1 callID=-1 |
|-----------------------------------------------------------------------|
|00001|00-1|02:18:47 AM|Attempting to determine application type via |
| | | |tropo-engine URL parameter in myURL |
|-----------------------------------------------------------------------|
|00002|00-1|02:18:47 AM|Attempting to determine application type by |
| | | |requesting HEAD from |
| | | |myURL to get Content-Type header |
|-----------------------------------------------------------------------|
|00003|00-1|02:18:47 AM|Opened URLConnection |
|-----------------------------------------------------------------------|
|00004|00-1|02:18:47 AM|Connecting for HEAD |
|-----------------------------------------------------------------------|
|00005|00-1|02:18:47 AM|Got HEAD response |
|-----------------------------------------------------------------------|
|00006|00-1|02:18:47 AM|No Content-Type header provided by HEAD. |
|-----------------------------------------------------------------------|
|00007|00-1|02:18:47 AM|Attempting to determine application type based |
| | | |on file extension for myURL |
|-----------------------------------------------------------------------|
|00008|00-1|02:18:47 AM|Determined type=php from filename suffix |
|-----------------------------------------------------------------------|
|00009|00-1|02:18:47 AM|Trying to create application for URL=myURL |
|-----------------------------------------------------------------------|
|00010|00-1|02:18:47 AM|Tropo app dir is /tropo_app_home |
|-----------------------------------------------------------------------|
|00011|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 sessionNumber=0 callID=0 |
|-----------------------------------------------------------------------|
|00012|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been |
| | | |created. |
|-----------------------------------------------------------------------|
|00013|0000|02:18:47 AM|Found hosted Application[myURL ver(1.0.56092) |
| | | |[token=myToken] |
|-----------------------------------------------------------------------|
|00014|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 sessionNumber=0 callID=0 |
|-----------------------------------------------------------------------|
|00015|0000|02:18:47 AM|Application[myURL ver(1.0.56092) has been found.|
|-----------------------------------------------------------------------|
|00016|0000|02:18:47 AM|Set logging context for http/0.0.0.0/8080-t-31 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 |
| | | |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |callID=0 |
|-----------------------------------------------------------------------|
|00017|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 acquired engine |
| | | |QuercusScriptEngine[] of type php, |
| | | |activeEngines = 5 |
|-----------------------------------------------------------------------|
|00018|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 got engine to |
| | | |compile script |
|-----------------------------------------------------------------------|
|00019|0000|02:18:47 AM|?><?php // line 1121 |
|-----------------------------------------------------------------------|
|00020|0000|02:18:47 AM|if ($currentCall != null) // line 1122 |
|-----------------------------------------------------------------------|
|00021|0000|02:18:47 AM|{ // line 1123 |
|-----------------------------------------------------------------------|
|00022|0000|02:18:47 AM| say("I'm sorry, but I can not find or |
| | | |compile the Tropo script for this phone number."|
| | | |); // line 1124 |
|-----------------------------------------------------------------------|
|00023|0000|02:18:47 AM| hangup(); // line 1125 |
|-----------------------------------------------------------------------|
|00024|0000|02:18:47 AM|} // line 1126 |
|-----------------------------------------------------------------------|
|00025|0000|02:18:47 AM|?> // line 1127 |
|-----------------------------------------------------------------------|
|00026|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returning engine |
| | | |after compiling script |
|-----------------------------------------------------------------------|
|00027|0000|02:18:47 AM|Thread http/0.0.0.0/8080-t-31 returned engine |
| | | |QuercusScriptEngine[] of type php, |
| | | |activeEngines = 4 |
|-----------------------------------------------------------------------|
|00028|0000|02:18:47 AM|In SimpleApplication.execute() for token launch,|
| | | |HttpSession |
| | | |hssn-9541A863A42B7294412DF27003FE67BF associated|
| | | |with SipApplicationSession |
| | | |sas_2-14-sm86gosslpnlz6tropo |
|-----------------------------------------------------------------------|
|00029|0000|02:18:47 AM|SipApplicationSession |
| | | |sas_2-14-sm86gosslpnlz6tropo associated with |
| | | |Tropo session a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00030|0000|02:18:47 AM|customerName:Kent is added into the context of |
| | | |app instance : ApplicationInstance[myURL, |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00031|0000|02:18:47 AM|numberToDial:2087401235 is added into the |
| | | |context of app instance : ApplicationInstance[ |
| | | |myURL , sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00032|0000|02:18:47 AM|action:create is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00033|0000|02:18:47 AM|format:xml is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00034|0000|02:18:47 AM|msg:XML Test is added into the context of app |
| | | |instance : ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00035|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] has been created. |
|-----------------------------------------------------------------------|
|00036|0000|02:18:47 AM|com.voxeo.tropo.core.SimpleCallFactory#44d6123f |
| | | |is added into the context of app instance : |
| | | |ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] |
|-----------------------------------------------------------------------|
|00037|0000|02:18:47 AM|Clearing logging context for |
| | | |http/0.0.0.0/8080-t-31 |
|-----------------------------------------------------------------------|
|00038|0000|02:18:47 AM|Set logging context for |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |to accountID=107029 host=tropo203.orl.voxeo.net |
| | | |sessionGUID=0 |
| | | |sessionNumber=a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |callID=-1 |
|-----------------------------------------------------------------------|
|00039|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] starts execution |
| | | |on Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00040|0000|02:18:47 AM|Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |acquired engine QuercusScriptEngine[] of type |
| | | |php, activeEngines = 5 |
|-----------------------------------------------------------------------|
|00041|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] replaced script |
| | | |engine [QuercusScriptEngine[]] --> |
| | | |[QuercusScriptEngine[]] in field <_engine> |
|-----------------------------------------------------------------------|
|00042|0000|02:18:47 AM|ApplicationInstance[myURL , |
| | | |sas_2-14-sm86gosslpnlz6tropo] ends execution on |
| | | |Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|
|00043|0000|02:18:47 AM|Thread |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |returned engine QuercusScriptEngine[] of type |
| | | |php, activeEngines = 4 |
|-----------------------------------------------------------------------|
|00044|0000|02:18:47 AM|sas_2-14-sm86gosslpnlz6tropo invalidated |
|-----------------------------------------------------------------------|
|00045|0000|02:18:47 AM|Instance a8f0ba032d2a377e8fdcc8b68d82c766 |
| | | |removed |
|-----------------------------------------------------------------------|
|00046|0000|02:18:47 AM|Clearing logging context for |
| | | |Tropo-Thread-a8f0ba032d2a377e8fdcc8b68d82c766 |
|-----------------------------------------------------------------------|

It looks like there are a few points of confusion/issues here, so I am going to try my best to tackle them all for you. The first thing I wanted to discuss is that the XML post to the session API is totally optional, it is just one way that you can submit your 'token request' to start an outbound call. If you are having issues getting this to work, let's just skip it and try a 'plane jane' HTTP GET straight from the browser until you are most comfortable:
api.tropo.com/1.0/sessions?action=create&token=123456&customerName=Kent&numberToDial=4075551212&msg=XML%20Test
Now on to the script itself, I found your accountID (yep, I work at Voxeo Labs / Tropo :P ), and I noticed a few things. First off you misspelled the application startURL, I am almost certain you meant ExternalPhoneHelper.php, but you typed ExterMalPhoneHelper.php, so you need to fix this first. Now the second thing, your file is actually blank, with the exception of the PHP tags.
So if you want to make a call and say something you can use call(); with a say(); or you can just use the combo/shortcut message(); method within your Tropo script:
<?php
message("Received office voice mail.", array("to" => "+14075550100"));
?>
Now on to the last question, How do you get your posted data in the Tropo application context? Well, the good news is that this is DEAD simple, we actually scope these as globals in your application, so the numberToDial query string parameter becomes $numberToDial, for example:
<?php
message($msg, array("to" => "+".$numberToDial));
?>
I really hope this helps, and if you still find yourself running into trouble hit up our support team, or find us in IRC on freenode (#tropo). My handle is dyer, and I am often in the channel lurking ;)
Take care!
-John

Related

PHP calculation different with SQL & Excel result

I tried to calculate using SQL and found out that the result was different with the excel one,
My table setting :
+--------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------------+---------------+------+-----+---------+----------------+
| qty_final | int(11) | NO | | NULL | |
| price_final_usd | decimal(20,2) | NO | | NULL | |
+--------------------+---------------+------+-----+---------+----------------+
My table content:
+-----------+-----------------+
| qty_final | price_final_usd |
+-----------+-----------------+
| 1 | 53.22 |
| 2 | 125.05 |
| 3 | 23.15 |
| 4 | 114.79 |
| 4 | 395.06 |
+-----------+-----------------+
my sql query :
UPDATE $table SET amount_final = round((qty_final * price_final_usd),2)
my php code :
$amount_final = round($qty_final * $price_final_usd, 2);
my excel formula :
=ROUND(qty_final * price_final_usd,2)
Here's the result comparison
Can someone tell me how to correct the PHP code ?
I want exactly the same result between them

Nested Resource : Missing required parameters (laravel)

I am quite new to Laravel, and to be honest - It is a great framework. I am however, a bit confused about some nested resources - including CRUD'ing them.
For routes I am using
Route::resource('startups','StartupsController');
Route::resource('startups.usecases','UsecasesController');
php artisan route:list
| | GET|HEAD | admin/startups | admin.startups.index | App\Http\Controllers\StartupsController#index | web,admin,auth:admin |
| | POST | admin/startups | admin.startups.store | App\Http\Controllers\StartupsController#store | web,admin,auth:admin |
| | GET|HEAD | admin/startups/create | admin.startups.create | App\Http\Controllers\StartupsController#create | web,admin,auth:admin |
| | DELETE | admin/startups/{startup} | admin.startups.destroy | App\Http\Controllers\StartupsController#destroy | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup} | admin.startups.show | App\Http\Controllers\StartupsController#show | web,admin,auth:admin |
| | PUT|PATCH | admin/startups/{startup} | admin.startups.update | App\Http\Controllers\StartupsController#update | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/edit | admin.startups.edit | App\Http\Controllers\StartupsController#edit | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases | admin.startups.usecases.index | App\Http\Controllers\UsecasesController#index | web,admin,auth:admin |
| | POST | admin/startups/{startup}/usecases | admin.startups.usecases.store | App\Http\Controllers\UsecasesController#store | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/create | admin.startups.usecases.create | App\Http\Controllers\UsecasesController#create | web,admin,auth:admin |
| | DELETE | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.destroy | App\Http\Controllers\UsecasesController#destroy | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.show | App\Http\Controllers\UsecasesController#show | web,admin,auth:admin |
| | PUT|PATCH | admin/startups/{startup}/usecases/{usecase} | admin.startups.usecases.update | App\Http\Controllers\UsecasesController#update | web,admin,auth:admin |
| | GET|HEAD | admin/startups/{startup}/usecases/{usecase}/edit | admin.startups.usecases.edit | App\Http\Controllers\UsecasesController#edit | web,admin,auth:admin |
For the parent, here called "startups", everything is fine, i can CRUD everything just fine.
For the child, here called "usecases", index, create, and store are fine. The moment I try to add a link to the edit, delete, or show within my templates I start getting : Missing required parameters for [Route: admin.startups.usecases.destroy] [URI: admin/startups/{startup}/usecases/{usecase}].
A link in my index blade file :
<li>Show</li>
returns that error.
In my UsecasesController
public function show($startup_id, $usecase_id)
{
$startups = $startup_id;
$usecase = Usecase::find($usecase_id);
return view('admin.startups.usecases.show')
->with('usecase', $usecase)
->with('startups', $startups);
}
TLDR: I can access and CRUD everything on parent, "startups". I can create and store for the child, but not edit, show, or delete - for "usecases".
Your help is appreciated.
You need to pass parameters as an array:
route('admin.startups.usecases.show', [$startup->id, $usecase->id])
And show() method will look like this:
public function show($startup, $usecase)
{
....

Get all dbpprops from a certain box in wikipedia

Let me use these 2 links as my examples:
http://en.wikipedia.org/wiki/Maarten_Stekelenburg
http://dbpedia.org/page/Maarten_Stekelenburg
What I want to do is get all the dbpprops which are in the top right infobox (the one with the picture).
Here I encounter 2 problems:
How do I get all the properties without knowing them (We are putting together a football player database, and the prop names are all different for every player)
How do I make sure those are the properties that are inside the box, because there are many other dbpprops on that page and it doesn't look like dbpedia differentiates between those.
After that I want to add all those properties to an array(if that is possible).
If it's possible, I would like it to look something like this:
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX dbp2: <http://dbpedia.org/ontology/>
PREFIX dbp3: <http://dbpedia.org/property/>
SELECT *
WHERE {
dbp:".$term." dbp2:abstract ?abstract .
dbp:".$term." dbp2:thumbnail ?img .
dbp:".$term." dbp3:* ?properties . //This would then be replaced by the necessary line
FILTER langMatches(lang(?abstract), 'en')
}
EDIT: I am working with PHP
I can't guarantee that the set of properties from the infobox will be exactly the properties that are dbpprop properties (as opposed to dbpedia-owl properties), but it looks like there's a fairly good correspondence. In this case, you could use a query like the following which asks for properties and values of the person you mentioned, but only thoe properties that are in the dbpprop namespace.
prefix dbpedia: <http://dbpedia.org/resource/>
prefix dbpprop: <http://dbpedia.org/property/>
select ?property ?value where {
dbpedia:Maarten_Stekelenburg ?property ?value
filter( strstarts(str(?property),str(dbpprop:)) )
}
SPARQL results
----------------------------------------------------------------------------------------------------------------------
| property | value |
======================================================================================================================
| dbpprop:bg | "gold"#en |
| dbpprop:bg | "#F1771D"#en |
| dbpprop:birthDate | "1982-09-21+02:00"^^<http://www.w3.org/2001/XMLSchema#date> |
| dbpprop:birthPlace | "Haarlem, Netherlands"#en |
| dbpprop:caps | 44 |
| dbpprop:caps | 191 |
| dbpprop:clubnumber | 24 |
| dbpprop:clubs | dbpedia:A.S._Roma |
| dbpprop:clubs | dbpedia:AFC_Ajax |
| dbpprop:currentclub | dbpedia:A.S._Roma |
| dbpprop:dateOfBirth | 22 |
| dbpprop:fg | "navy"#en |
| dbpprop:fg | "white"#en |
| dbpprop:fullname | "Maarten Stekelenburg"#en |
| dbpprop:goals | 0 |
| dbpprop:name | "Maarten Stekelenburg"#en |
| dbpprop:name | "Stekelenburg, Maarten"#en |
| dbpprop:nationalcaps | 4 |
| dbpprop:nationalcaps | 54 |
| dbpprop:nationalgoals | 0 |
| dbpprop:nationalteam | dbpedia:Netherlands_national_football_team |
| dbpprop:nationalteam | dbpedia:Netherlands_national_under-21_football_team |
| dbpprop:nationalyears | 2002 |
| dbpprop:nationalyears | 2004 |
| dbpprop:ntupdate | 18 |
| dbpprop:pcupdate | 21 |
| dbpprop:placeOfBirth | "Haarlem, Netherlands"#en |
| dbpprop:position | <http://dbpedia.org/resource/Goalkeeper_(association_football)> |
| dbpprop:shortDescription | "Dutch footballer"#en |
| dbpprop:title | "Awards"#en |
| dbpprop:title | "Netherlands squads"#en |
| dbpprop:years | 2002 |
| dbpprop:years | 2011 |
| dbpprop:youthclubs | dbpedia:AFC_Ajax |
| dbpprop:youthclubs | "Schoten"#en |
| dbpprop:youthclubs | "Zandvoort '75"#en |
| dbpprop:youthyears | 1997 |
| dbpprop:wordnet_type | <http://www.w3.org/2006/03/wn/wn20/instances/synset-soccer_player-noun-1> |
| dbpprop:hasPhotoCollection | <http://wifo5-03.informatik.uni-mannheim.de/flickrwrappr/photos/Maarten_Stekelenburg> |
----------------------------------------------------------------------------------------------------------------------
You mentioned storing results in an array, but I don't really understand the example that you've provided. It looks more like a query than code to put something into an array. Additionally, you haven't specified what programming language you're working with, so we can't really respond with array manipulation code.

pulling from a specific data from a row and column in a database

My data base looks like this.
its ordered ascending by NO#
And col2 is the start of the database NO# is basically invisible and only used as a reference as to row number
so lets say I wanted to display on a web page the text in col8, row 5. What would the php code be?
PS. the connect code is seperate and not an issue hence i did not include itI
-|NO#|col2|col3|col4|col5|col6|col7|col8|col9|col10
---------------------------------------------------
|1 | | | | | | | | | |
---------------------------------------------------
|2 | | | | | | | | | |
---------------------------------------------------
|3 | | | | | | | | | |
---------------------------------------------------
|4 | | | | | | | | | |
---------------------------------------------------
|5 | | | | | | |2012| | |
---------------------------------------------------
|6 | | | | | | | | | |
---------------------------------------------------
|7 | | | | | | | | | |
---------------------------------------------------
|8 | | | | | | | | | |
---------------------------------------------------
|9 | | | | | | | | | |
---------------------------------------------------
|10 | | | | | | | | | |
---------------------------------------------------
Here is my code but it whites out the page when I try to load it.
<?php
//selects row
$query = "SELECT * FROM `Inventory` WHERE NO# = '5'";
//select column
$col8 = $row['col8'];
// fetch the results
WHILE($row = mysql_fetch_array($query):
$row = mysql_fetch_array($result);
// display the results
<div id="year">echo "$col8";</div>
?>
I would probably do something like what's below. I have not tested this code, though.
<?php
$result = mysql_query( "SELECT `col8` FROM `Inventory` WHERE `NO#` = '5' LIMIT 1" );
$row = mysql_fetch_assoc( $result );
?>
<div id="year"><?php echo $row['col8']; ?></div>
Hopefully that'll help you out a bit.

My table in postgresql is truncating these strings

I have a table in VMobjects like this
MGRCONFIG_DB=# select * from vmobjects;
guid | ipaddress | username | password | hostid | vmname | guestostype | guestos
name
-----------------------------------+---------------+----------+----------+----------+-----------------+-------------+--------
-----
7728235734dcd25700e7c02.96324791 | gsdag | gsdasd | | Physical | rag | windows |
3642656604dcd343d3bcd11.54875889 | fsd | | | Physical | derde | windows |
17714467484dcd35dd0fa677.27764184 | dsf | | | Physical | fdsfd | windows |
1837080764dcd362fafe404.83675706 | fgf | | | Physical | fgf | windows |
2791118544dcd363df11bf1.21924610 | fdghhg | | | Physical | $%^ | windows |
7716352574dcd365c9eb777.30236042 | dsffd | | | Physical | ^ | windows |
10753160514dcd366631f5b6.48505657 | gfdgd | | | Physical | # | windows |
8253046164dcd366f177bc3.85542378 | ghgfdhg | | | Physical | ############## | windows |
9126180214dcd367a5b42e0.23605256 | fsdfdsfdsf | | | Physical | fdsaj;( | windows |
11086632854dcd36f62f7e79.14470771 | dfsdfsd | | | Physical | ^ | windows |
Now I have a php page addvm.php, when I add username/ip/password/ or anything it gets truncated
gets truncated on entering data as '~!##$%^&*()_+=-`{}|\][:"';<>?/.,' for all fields.
After using pg_escape_string
i am able to insert '~!##$%^()_=-`{}|][:"';<>?/. all strings except + and &.
#Emil Vikström: say that i have to use urlencode for this. but i don't no, How & whr it is used?
Use pg_escape_string on the data before entering it into your SQL query:
$data = '~!##$%^&*()_+=-';
$data_escaped = pg_escape_string($data);
$query = 'INSERT INTO table (data) VALUES("'. $data_escaped .'");';

Categories