[PHP-users 13849] Re: SQL$BJ8$N:n@.!J407k!K(B

tamura php-users@php.gr.jp
Sun, 09 Mar 2003 01:23:22 +0900


$BEDB<$G$9!"$^$$$I!#(B

$B%-%?%`%i$5$s!"$"$j$,$H$&$4$6$$$^$9!#(B
> >> $B<B9TIt$K=q$$$F$&$^$/9T$C$?$N$O!"(B
> >>
> >>> $set .= (strlen($dat) == 0)? "{$key}=NULL,": "{$key}='${$dat}',";
> >>
> >> $B$N!V(B${$dat}$B!W$G8F$S=P$5$l$kJQ?t$,4X?t$NCf$+$i$O8+$($J$+$C$?$+$i$@$H(B
> >
> > $B!!$3$&$$$&$3$H$r%;%C%7%g%s$,@Z$l$k$H8@$&$N$G$9$+!#(B
> 
> $B$$$(!"$3$N>l9g$O!VJQ?t$N%9%3!<%W(B($BM-8zHO0O(B) $B$,0c$&$N$G;2>H$G$-$J$+$C$?!W$G$9!#(B

$B!!$O$$!"$J$k$[$I!#(B

> 
> 
> >> $B<B9T$9$k%9%/%j%W%H$N@hF,$K(B
> >>
> >> error_reporting(E_ALL);
> >>
> >> $B$rDI2C$9$l$P!"L$Dj5AJQ?t$N%(%i!<$H$+A4$F$N%(%i!<$,8+$l$^$9$h!#(B
> >
> > $B!!5-F~$9$k>l=j$rA*$P$J$$!JEvA3$G$9$,!K$H!"B?$/$N7Y9p$K6C$+$5$l$^$7$?!#$H(B
> > $B$j$o$1!"(BINSERT $BMQ$K;H$&(B
> 
> $B$(!A$C$H!"$O$8$a$F(BE_ALL$B$K$7$F6C$+$l$?$H;W$$$^$9$,!"=PNO$5$l$?%a%C%;!<%8$O(B
> $BA4$F$=$N%W%m%0%i%`$,(B($B$J$K$+$7$i(B)$B$*$+$7$$$H8@$C$F$$$k$N$G!"%a%C%;!<%8$,=PNO(B
> $B$5$l$J$$$h$&$K%W%m%0%i%_%s%0$7$?J}$,$$$$$G$9!#(B

$B!!$O$$!"%G%P%C%0$7$F$$$-$^$9!#(B
> 
> $B:#2s$N%(%i!<$b!"=i4|2=$5$l$F$$$J$$JQ?t$N;2>H$OM=4|$7$J$$(B($BH/8+$7$K$/$$(B)$B%P%0(B
> $B$N:n$j9~$_$d%;%-%e%j%F%#%[!<%k$K$J$C$?$j$7$^$9!#(B
> 
> 
> > $B!!ApFe$5$s$+$i!"65$o$C$?2DJQJQ?t$J$k$b$N$b$7$F$_$?$$$7!";E;v$b$"$k$o!"$3(B
> > $B$j$c!"K;$7$$$3$H$K$J$C$F$-$^$7$?!JFH$j8@!"%4%a%s!K!#(B

$B!!ApFe$5$s$N%"%I%P%$%9$G!"40A4$KHFMQ$K$J$j$^$7$?!#$3$N$3$H$O!":G8e$K=q$-(B
$B$^$9!#(B

> $BK;$7$$$H$3$mBgJQ$G$9$,!"(BPHP$B4X78$NK\$r#1:}DL$7$FFI$`;v$r$*$9$9$a$7$^$9!#$H$j(B
> $B$"$($:!V@V%^%s%b%9K\!W$G$9$+$M!"JQ?t$N%9%3!<%W$N;v$b=q$$$F$^$9$h!#(B

$B!!$O$$!"5a$a$^$9!#(B


$B!!ApFe$5$s!"$"$j$,$H$&$4$6$$$^$7$?!#2DJQJQ?t$NJY6/$I$3$m$+!"%3!<%I$^$G$$(B
$B$?$@$$$F$*$j!">/$7$N<jD>$7$G!";W$$DL$j$K9T$-$^$7$?!#!J4X?t$r;HMQ$7$J$$!K(B
$B!!$*$^$1$O!"$=$N$*0~$G!P(B $B!V(B,=NULL$B!W$NItJ,$,<YKb$r$7$F!"F0$-$^$;$s!#!Q$^(B
$B$G!"2r7h$7$^$7$?!#(B

$B0J2<$O<B9TIt$9$Y$F$G$9!#(B

    $cnt      = 0;
    $COL_DATS = array();
    $result   = mysql_list_fields( $dbname, $tbname, $conn);
    while ( $cnt < mysql_num_fields( $result)) {
      $fdname[$cnt]            = mysql_fieldname( $result, $cnt);
      $COL_DATS[$fdname[$cnt]] = ${$fdname[$cnt]};
      ++$cnt;
    }
    $where = "$fdname[0]=".${$fdname[0]};
    $i=0;
    $set = ' SET ';
    foreach ($COL_DATS as $key => $dat){
      $set .= (strlen($dat) == 0)? "{$key}=NULL,": "{$key}='{$dat}',";
      $i++;
    }
    $set = chop($set, ',');
    $sql  = 'UPDATE '.$tbname.$set.' where '.$where;
    $result = mysql_query($sql);
    echo "Record updated";

$B!!%-%?%`%i$5$s!"ApFe$5$s!"3'$5$sK\Ev$K$"$j$,$H$&$4$6$$$^$7$?!#(B