Search Postgresql Archives

Re: problem with serial

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





2012/4/19 Chris Angelico <rosuav@xxxxxxxxx>

No; ditch them. I mean no offense to you personally, but these
functions are not worth keeping. Every SQL API includes a function for
quoting something as a literal string. With PDO, it's this one:

http://www.php.net/manual/en/pdo.quote.php

I don't know where you would be using sql2str, but it's just as
dangerous as the others (not to mention inefficient, there's no need
to use regular expressions for simple string replacement). Replace all
your calls to any of these functions with standard quoting functions
and see if your problem disappears. If not, well, it's still not been
a fruitless exercise, because now you are relying for safety and
security on something that the database engine promises is correct :)

OK, OK, this comes from an old workaround with SQLite3...

I put the query into a try / catch like that :
          $sql="INSERT INTO categories (idx, ctime, mtime, name) VALUES ( $idx, '$dat', '$dat', '".str2sql(quoteAsAre($name))."' ) RETURNING rowid;";
          $xml.="<sql>$sql</sql>";
          try {
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $ret=$db->query($sql);
            $row=$ret->fetch();
            $rowid=$row['rowid'];
            $xml.="<rowid>$rowid</rowid>";
          } catch (PDOException $e) {
            $xml.="<PDOException>".$e->getMessage()."</PDOException>";
          }

with that i can read the sql and the error.

I'l follow your advice about quoting, ASAP )))

--
Yvon



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux