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,837 of 264,096    |
|    =?UTF-8?Q?Arne_Vajh=C3=B8j?= to All    |
|    Re: VMS x86-64 database server    |
|    10 Jul 25 19:57:32    |
   
   From: arne@vajhoej.dk   
      
   On 7/9/2025 10:24 PM, Arne Vajhøj wrote:   
   > PHP give you the choice of which you want (for mysqli and pdo mysql   
   > and many other).   
   >   
   > $ type err1.php   
   >    
   > $con = mysqli_connect('arnepc5', 'arne', 'hemmeligt', 'test');   
   > mysqli_report(MYSQLI_REPORT_OFF);   
   > $stmt = mysqli_prepare($con, 'SELECT the data needed');   
   > if(!$stmt) {   
   > echo mysqli_error($con) . "\r\n";   
   > goto closecon;   
   > }   
   > // whatever   
   > closestmt: mysqli_stmt_close($stmt);   
   > closecon: mysqli_close($con);   
   > ?>   
   > $ php err1.php   
   > You have an error in your SQL syntax; check the manual that corresponds   
   > to your MySQL server version for the right syntax to use near 'needed'   
   > at line 1   
   > $ type err2.php   
   >    
   > $con = mysqli_connect('arnepc5', 'arne', 'hemmeligt', 'test');   
   > mysqli_report(MYSQLI_REPORT_ALL);   
   > try {   
   > $stmt = mysqli_prepare($con, 'SELECT the data needed');   
   > // whatever   
   > mysqli_stmt_close($stmt);   
   > mysqli_close($con);   
   > } catch (mysqli_sql_exception $ex) {   
   > echo $ex->getMessage() . "\r\n";   
   > mysqli_close($con);   
   > }   
   > ?>   
   > $ php err2.php   
   > You have an error in your SQL syntax; check the manual that corresponds   
   > to your MySQL server version for the right syntax to use near 'needed'   
   > at line 1   
   >   
   > Default in recent PHP versions is exceptions.   
      
   If someone want the same using PDO.   
      
   (and yes - everybody should use PDO instead of mysqli!)   
      
   $ type err3.php   
   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;   
   }   
   // whatever   
   finish:   
   ?>   
   $ php err3.php   
   You have an error in your SQL syntax; check the manual that corresponds   
   to your MySQL server version for the right syntax to use ne   
   ar 'needed' at line 1   
   $ type err4.php   
   setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);   
   try {   
    $stmt = $con->prepare('SELECT the data needed');   
    $stmt->execute();   
    // whatever   
   } catch (PDOException $ex) {   
    echo $ex->getMessage() . "\r\n";   
   }   
   ?>   
   $ php err4.php   
   SQLSTATE[42000]: Syntax error or access violation: 1064 You have an   
   error in your SQL syntax; check the manual that corresponds to   
   your MySQL server version for the right syntax to use near 'needed' at   
   line 1   
      
   Arne   
      
   --- 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