Forums before death by AOL, social media and spammers... "We can't have nice things"
|    comp.os.vms    |    DEC's VAX* line of computers & VMS.    |    264,096 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 262,842 of 264,096    |
|    Lawrence D'Oliveiro to All    |
|    Re: VMS x86-64 database server    |
|    11 Jul 25 00:24:17    |
   
   From: ldo@nz.invalid   
      
   On Thu, 10 Jul 2025 19:57:32 -0400, Arne Vajhøj wrote:   
      
   > (and yes - everybody should use PDO instead of mysqli!)   
   >   
   > $con = new PDO('mysql:host=arnepc5;dbname=test', 'arne', 'hemmeligt');   
   > $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);   
   > $stmt = $con->prepare('SELECT the data needed');   
   > if(!$stmt) {   
   > echo $con->errorInfo()[2] . "\r\n";   
   > goto finish;   
   > }   
   > if(!$stmt->execute()) {   
   > echo $stmt->errorInfo()[2] . "\r\n";   
   > goto finish;   
   > }   
      
   That is so clunky without exceptions. You’d think normal programmers   
   would get fed up of continually writing prepare/execute/fetch   
   sequences. But PHP programmers don’t seem to think like normal people.   
      
   Here’s a utility function I wrote for my Python code years ago, and   
   use every time I want to retrieve data from an SQL database. This is   
   the SQLite version using the APSW wrapper:   
      
    def db_iter(conn, cmd, values = None, mapfn = lambda x : x) :   
    "executes cmd on a new cursor from connection conn and yields" \   
    " the results in turn."   
    for item in conn.cursor().execute(cmd, values) :   
    yield mapfn(item)   
    #end for   
    #end db_iter   
      
   So getting and processing records is as simple as   
      
    for entry in db_iter(conn, "select ..." ...) :   
    ... do something with entry ...   
    #end for   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca