com doc/ja: Remove try-catch from PDO examples: reference/pdo/pdo/construct.xml reference/pdo/pdostatement/bindcolumn.xml reference/pdo/pdostatement/fetch.xml reference/pdo/pdostatement/setfetchmode.xml

[email protected] (Yoshinari Takaoka) Tue, 09 Mar 2021 11:18:45 +0000
Newsgroups php.doc.ja
Message-ID <[email protected]>
Commit:    832a1c0e76f925399e5c641f32affb3870a6a51d=0AAuthor:    Yoshinari =
Takaoka <[email protected]>         Tue, 9 Mar 2021 20:18:45 +0900=0AParent=
s:   612f97c95a7f1fa7b155911294af8ada31ff9747=0ABranches:  master=0A=0ALink=
:       http://git.php.net/?p=3Ddoc/ja.git;a=3Dcommitdiff;h=3D832a1c0e76f92=
5399e5c641f32affb3870a6a51d=0A=0ALog:=0ARemove try-catch from PDO examples=
=0A=0AAlso fix erroneous indentation.=0A=0ACo-authored-by: Anna Filina <afi=
[email protected]>=0A=0ACloses GH-323.=0A=0AChanged paths:=0A  M  reference/pd=
o/pdo/construct.xml=0A  M  reference/pdo/pdostatement/bindcolumn.xml=0A  M =
 reference/pdo/pdostatement/fetch.xml=0A  M  reference/pdo/pdostatement/set=
fetchmode.xml=0A=0A=0ADiff:=0Adiff --git a/reference/pdo/pdo/construct.xml =
b/reference/pdo/pdo/construct.xml=0Aindex 480b71f84c..e4ea4c375b 100644=0A-=
-- a/reference/pdo/pdo/construct.xml=0A+++ b/reference/pdo/pdo/construct.xm=
l=0A@@ -1,6 +1,6 @@=0A <?xml version=3D"1.0" encoding=3D"utf-8"?>=0A <!-- $=
Revision$ -->=0A-<!-- EN-Revision: 7f569e1f175adf1fbd0e462eba8d6bc82214c939=
 Maintainer: takagi Status: ready -->=0A+<!-- EN-Revision: a3a310ccc23af271=
0c307fb4c6535b123ae2223c Maintainer: takagi Status: ready -->=0A <!-- CREDI=
TS: hirokawa,shimooka,mumumu -->=0A <refentry xml:id=3D"pdo.construct" xmln=
s=3D"http://docbook.org/ns/docbook">=0A  <refnamediv>=0A@@ -117,6 +117,7 @@=
=0A   <para>=0A    <function>PDO::__construct</function> =E3=81=AF=E3=80=
=81=0A    =E6=8C=87=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=9F=E3=83=87=E3=83=
=BC=E3=82=BF=E3=83=99=E3=83=BC=E3=82=B9=E3=81=B8=E3=81=AE=E6=8E=A5=E7=B6=
=9A=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=97=E3=81=9F=E5=A0=B4=E5=90=88=E3=80=
=81=0A+   <constant>PDO::ATTR_ERRMODE</constant> =E3=81=8C=E8=A8=AD=
=E5=AE=9A=E3=81=95=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E3=81=8B=E3=81=A9=
=E3=81=86=E3=81=8B=E3=81=AB=E9=96=A2=E3=82=8F=E3=82=89=E3=81=9A=E3=80=81=0A=
    <classname>PDOException</classname> =E3=82=92=E6=8A=95=E3=81=92=
=E3=81=BE=E3=81=99=E3=80=82=0A   </para>=0A  </refsect1>=0A@@ -133,11 +134,=
7 @@ $dsn =3D 'mysql:dbname=3Dtestdb;host=3D127.0.0.1';=0A $user =3D 'dbuse=
r';=0A $password =3D 'dbpass';=0A =0A-try {=0A-    $dbh =3D new PDO($dsn, $=
user, $password);=0A-} catch (PDOException $e) {=0A-    echo 'Connection fa=
iled: ' . $e->getMessage();=0A-}=0A+$dbh =3D new PDO($dsn, $user, $password=
);=0A =0A ?>=0A ]]>=0A@@ -167,11 +164,7 @@ $dsn =3D 'uri:file:///usr/local/=
dbconnect';=0A $user =3D '';=0A $password =3D '';=0A =0A-try {=0A-    $dbh =
=3D new PDO($dsn, $user, $password);=0A-} catch (PDOException $e) {=0A-    =
echo 'Connection failed: ' . $e->getMessage();=0A-}=0A+$dbh =3D new PDO($ds=
n, $user, $password);=0A =0A ?>=0A ]]>=0A@@ -195,11 +188,7 @@ $dsn =3D 'myd=
b';=0A $user =3D '';=0A $password =3D '';=0A =0A-try {=0A-    $dbh =3D new =
PDO($dsn, $user, $password);=0A-} catch (PDOException $e) {=0A-    echo '=
=E6=8E=A5=E7=B6=9A=E3=81=AB=E5=A4=B1=E6=95=97=E3=81=97=E3=81=BE=E3=81=97=
=E3=81=9F: ' . $e->getMessage();=0A-}=0A+$dbh =3D new PDO($dsn, $user, $pas=
sword);=0A =0A ?>=0A ]]>=0Adiff --git a/reference/pdo/pdostatement/bindcolu=
mn.xml b/reference/pdo/pdostatement/bindcolumn.xml=0Aindex 231cb405b7..74a4=
39e377 100644=0A--- a/reference/pdo/pdostatement/bindcolumn.xml=0A+++ b/ref=
erence/pdo/pdostatement/bindcolumn.xml=0A@@ -1,6 +1,6 @@=0A <?xml version=
=3D"1.0" encoding=3D"utf-8"?>=0A <!-- $Revision$ -->=0A-<!-- EN-Revision: 1=
4af302c9c0e561fa6f9cdd956268758ba9a89c5 Maintainer: takagi Status: ready --=
>=0A+<!-- EN-Revision: a3a310ccc23af2710c307fb4c6535b123ae2223c Maintainer:=
 takagi Status: ready -->=0A <!-- CREDITS: shimooka -->=0A <refentry xml:id=
=3D"pdostatement.bindcolumn" xmlns=3D"http://docbook.org/ns/docbook">=0A  <=
refnamediv>=0A@@ -122,33 +122,23 @@=0A     <programlisting role=3D"php">=0A=
 <![CDATA[=0A <?php=0A-function readData($dbh) {=0A-  $sql =3D 'SELECT name=
, colour, calories FROM fruit';=0A-  try {=0A-    $stmt =3D $dbh->prepare($=
sql);=0A-    $stmt->execute();=0A+$stmt =3D $dbh->prepare('SELECT name, col=
our, calories FROM fruit');=0A+$stmt->execute();=0A =0A-    /* =E3=82=AB=
=E3=83=A9=E3=83=A0=E7=95=AA=E5=8F=B7=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=
=E3=83=90=E3=82=A4=E3=83=B3=E3=83=89=E3=81=99=E3=82=8B */=0A-    $stmt->bin=
dColumn(1, $name);=0A-    $stmt->bindColumn(2, $colour);=0A-    =0A-    /* =
=E3=82=AB=E3=83=A9=E3=83=A0=E5=90=8D=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=
=E3=83=90=E3=82=A4=E3=83=B3=E3=83=89=E3=81=99=E3=82=8B */=0A-    $stmt->bin=
dColumn('calories', $cals);=0A+/* =E3=82=AB=E3=83=A9=E3=83=A0=E7=95=AA=
=E5=8F=B7=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=E3=83=90=E3=82=A4=E3=83=B3=
=E3=83=89=E3=81=99=E3=82=8B */=0A+$stmt->bindColumn(1, $name);=0A+$stmt->bi=
ndColumn(2, $colour);=0A =0A-    while ($row =3D $stmt->fetch(PDO::FETCH_BO=
UND)) {=0A-      $data =3D $name . "\t" . $colour . "\t" . $cals . "\n";=0A=
-      print $data;=0A-    }=0A-  }=0A-  catch (PDOException $e) {=0A-    p=
rint $e->getMessage();=0A-  }=0A+/* =E3=82=AB=E3=83=A9=E3=83=A0=E5=90=8D=
=E3=81=AB=E3=82=88=E3=81=A3=E3=81=A6=E3=83=90=E3=82=A4=E3=83=B3=E3=83=89=
=E3=81=99=E3=82=8B */=0A+$stmt->bindColumn('calories', $cals);=0A+=0A+while=
 ($stmt->fetch(PDO::FETCH_BOUND)) {=0A+    print $name . "\t" . $colour . "=
\t" . $cals . "\n";=0A }=0A-readData($dbh);=0A ?>=0A   ]]>=0A     </program=
listing>=0A-    &example.outputs;=0A+    &example.outputs.similar;=0A     <=
screen>=0A <![CDATA[=0A apple   red     150=0Adiff --git a/reference/pdo/pd=
ostatement/fetch.xml b/reference/pdo/pdostatement/fetch.xml=0Aindex ff9968d=
a7c..84c775ff4d 100644=0A--- a/reference/pdo/pdostatement/fetch.xml=0A+++ b=
/reference/pdo/pdostatement/fetch.xml=0A@@ -1,7 +1,7 @@=0A <?xml version=3D=
"1.0" encoding=3D"utf-8"?>=0A <!-- $Revision$ -->=0A-<!-- EN-Revision: e440=
c79af15cf829549736b2a292b5f8f6887142 Maintainer: takagi Status: ready -->=
=0A-<!-- CREDITS: hirokawa -->=0A+<!-- EN-Revision: a3a310ccc23af2710c307fb=
4c6535b123ae2223c Maintainer: takagi Status: ready -->=0A+<!-- CREDITS: hir=
okawa,mumumu -->=0A <refentry xml:id=3D"pdostatement.fetch" xmlns=3D"http:/=
/docbook.org/ns/docbook">=0A  <refnamediv>=0A   <refname>PDOStatement::fetc=
h</refname>=0A@@ -219,35 +219,23 @@ kiwi=0A <![CDATA[=0A <?php=0A function =
readDataForwards($dbh) {=0A-  $sql =3D 'SELECT hand, won, bet FROM mynumber=
s ORDER BY BET';=0A-  try {=0A+    $sql =3D 'SELECT hand, won, bet FROM myn=
umbers ORDER BY BET';=0A     $stmt =3D $dbh->prepare($sql, array(PDO::ATTR_=
CURSOR =3D> PDO::CURSOR_SCROLL));=0A     $stmt->execute();=0A     while ($r=
ow =3D $stmt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_NEXT)) {=0A-      $data =
=3D $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";=0A-      print $data;=
=0A+        $data =3D $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";=0A+=
        print $data;=0A     }=0A-    $stmt =3D null;=0A-  }=0A-  catch (PDO=
Exception $e) {=0A-    print $e->getMessage();=0A-  }=0A }=0A function read=
DataBackwards($dbh) {=0A-  $sql =3D 'SELECT hand, won, bet FROM mynumbers O=
RDER BY bet';=0A-  try {=0A+    $sql =3D 'SELECT hand, won, bet FROM mynumb=
ers ORDER BY bet';=0A     $stmt =3D $dbh->prepare($sql, array(PDO::ATTR_CUR=
SOR =3D> PDO::CURSOR_SCROLL));=0A     $stmt->execute();=0A     $row =3D $st=
mt->fetch(PDO::FETCH_NUM, PDO::FETCH_ORI_LAST);=0A     do {=0A-      $data =
=3D $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";=0A-      print $data;=
=0A+        $data =3D $row[0] . "\t" . $row[1] . "\t" . $row[2] . "\n";=0A+=
        print $data;=0A     } while ($row =3D $stmt->fetch(PDO::FETCH_NUM, =
PDO::FETCH_ORI_PRIOR));=0A-    $stmt =3D null;=0A-  }=0A-  catch (PDOExcept=
ion $e) {=0A-    print $e->getMessage();=0A-  }=0A }=0A =0A print "Reading =
forwards:\n";=0Adiff --git a/reference/pdo/pdostatement/setfetchmode.xml b/=
reference/pdo/pdostatement/setfetchmode.xml=0Aindex f3c89f34ab..736e1a6993 =
100644=0A--- a/reference/pdo/pdostatement/setfetchmode.xml=0A+++ b/referenc=
e/pdo/pdostatement/setfetchmode.xml=0A@@ -1,6 +1,6 @@=0A <?xml version=3D"1=
.0" encoding=3D"utf-8" ?>=0A <!-- $Revision$ -->=0A-<!-- EN-Revision: 9267d=
8b70e8fa541c5d464e56f94fef7b1b1a849 Maintainer: takagi Status: ready -->=0A=
+<!-- EN-Revision: a3a310ccc23af2710c307fb4c6535b123ae2223c Maintainer: tak=
agi Status: ready -->=0A <!-- CREDITS: shimooka,mumumu -->=0A <refentry xml=
:id=3D"pdostatement.setfetchmode" xmlns=3D"http://docbook.org/ns/docbook">=
=0A  <refnamediv>=0A@@ -105,18 +105,11 @@=0A     <programlisting role=3D"ph=
p">=0A <![CDATA[=0A <?php=0A-$sql =3D 'SELECT name, colour, calories FROM f=
ruit';=0A-try {=0A-  $stmt =3D $dbh->query($sql);=0A-  $result =3D $stmt->s=
etFetchMode(PDO::FETCH_NUM);=0A-  while ($row =3D $stmt->fetch()) {=0A+$stm=
t =3D $dbh->query('SELECT name, colour, calories FROM fruit');=0A+$stmt->se=
tFetchMode(PDO::FETCH_NUM);=0A+foreach ($stmt as $row) {=0A     print $row[=
0] . "\t" . $row[1] . "\t" . $row[2] . "\n";=0A-  }=0A }=0A-catch (PDOExcep=
tion $e) {=0A-  print $e->getMessage();=0A-}=0A-?>=0A ]]>=0A     </programl=
isting>=0A     &example.outputs;=0A@@ -128,7 +121,6 @@ orange  orange  300=
=0A kiwi    brown   75=0A lemon   yellow  25=0A pear    green   150=0A-wate=
rmelon      pink    90=0A ]]>=0A     </screen>=0A    </example>=0A