Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7400 > unrolled thread
| Started by | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| First post | 2012-10-30 13:05 +0100 |
| Last post | 2012-11-02 20:27 +0100 |
| Articles | 6 — 4 participants |
Back to article view | Back to comp.lang.php
adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-30 13:05 +0100
Re: adding a method to a built-in class ? "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-10-30 13:38 +0100
Re: adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-30 14:42 +0100
Re: adding a method to a built-in class ? Gregor Kofler <usenet@gregorkofler.com> - 2012-10-31 11:09 +0100
Re: adding a method to a built-in class ? Une Bévue <unbewusst.sein@fai.invalid> - 2012-10-31 15:08 +0100
Re: adding a method to a built-in class ? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-11-02 20:27 +0100
| From | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| Date | 2012-10-30 13:05 +0100 |
| Subject | adding a method to a built-in class ? |
| Message-ID | <508fc27f$0$1948$426a74cc@news.free.fr> |
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 "''".
[toc] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-10-30 13:38 +0100 |
| Message-ID | <afa034FoaloU1@mid.uni-berlin.de> |
| In reply to | #7400 |
Am 30.10.2012 13:05, schrieb Une Bévue: > 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 "''". It looks like you want to program your own sql parameter substitution. You should rather use the functions like mysqli::real_escape_string(), PDO::quote(), or use prepared statements. /Str.
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| Date | 2012-10-30 14:42 +0100 |
| Message-ID | <508fd92b$0$1866$426a74cc@news.free.fr> |
| In reply to | #7401 |
Le 30/10/2012 13:38, M. Strobel a écrit : > It looks like you want to program your own sql parameter substitution. You should > rather use the functions like mysqli::real_escape_string(), PDO::quote(), or use > prepared statements. fine, thanks a lot ! easier to work with ;-)
[toc] | [prev] | [next] | [standalone]
| From | Gregor Kofler <usenet@gregorkofler.com> |
|---|---|
| Date | 2012-10-31 11:09 +0100 |
| Message-ID | <k6qtdk$79q$1@dont-email.me> |
| In reply to | #7400 |
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. Gregor
[toc] | [prev] | [next] | [standalone]
| From | Une Bévue <unbewusst.sein@fai.invalid> |
|---|---|
| Date | 2012-10-31 15:08 +0100 |
| Message-ID | <509130e4$0$14776$426a74cc@news.free.fr> |
| In reply to | #7407 |
Le 31/10/2012 11:09, Gregor Kofler a écrit : > 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. OK, fine, i'll be using $conn->quote($aString); Thanks
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-11-02 20:27 +0100 |
| Message-ID | <3288477.yfRR5QZLSb@PointedEars.de> |
| In reply to | #7407 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web