我在这样的VMobjects中有一个表
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 |
现在我有一个php页面addvm.php
,当我添加username/ip/password/
或被截断的任何内容时
gets truncated on entering data as '~!@#$%^&*()_+=-`{}|\][:"';<>?/.,' for all fields.
使用pg_escape_string后 我可以插入'〜!@#$%^()_ = - `{} |] [:“';&lt;&gt;?/。除+和&amp;之外的所有字符串。 @EmilVikström:说我必须使用urlencode。但我不,不,如何&amp;它被使用了吗?
答案 0 :(得分:3)
在将数据输入SQL查询之前对数据使用pg_escape_string:
$data = '~!@#$%^&*()_+=-';
$data_escaped = pg_escape_string($data);
$query = 'INSERT INTO table (data) VALUES("'. $data_escaped .'");';