Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3288477.yfRR5QZLSb@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Fri, 02 Nov 2012 20:27:17 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. Followup-To: comp.lang.php MIME-Version: 1.0 Lines: 33 NNTP-Posting-Date: 02 Nov 2012 20:27:17 CET NNTP-Posting-Host: 0cab920a.newsspool2.arcor-online.net X-Trace: DXC=`X^Y:\;\]?KlU`@c^jLCbJA9EHlD;3YcB4Fo<]lROoRA8kFK@ehLF0A91V>HoWDE7??^\5D X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.php:7434 Gregor Kofler wrote: > Am 2012-10-30 13:05, Une Bévue meinte: > > newbie to php5, i'd like to know if i could add a method to a built-in > > class. > > > > The purpose is to ass #to_sql() method to the String class. > > > > #to_sql() would just replace any oiccurence of the character "'" by two > > of it "''". > > There is no such thing as a "string class" in PHP (apart from an > experimental SplString class). However, you can extend the already > mentioned Mysqli and Pdo classes and create subclasses tailored to your > needs. However, in this particular case that would be unwise, because that user- defined to_sql() method would hardly be sufficient to escape string values in SQL statements safely, and it would most likely be unnecessary to write in the first place. The OP should look into mysql_real_escape_string() if they have to use the `mysql' extension, or learn about Prepared Statements (PS) if they can use the `mysqli' extension or PDO, instead. A solution with PS is strongly recommended. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee