728x90

mcrypt.so 확장 모듈 추가하기

 

이것은 CBC에서 DES, TripleDES, Blowfish (기본값), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 및 GOST와 같은 다양한 블록 알고리즘을 지원하는 암호화 모듈입니다.

또한 "무료"로 사용할 수 있었던 RC6 및 IDEA를 지원합니다.

CFB / OFB는 기본적으로 8 비트입니다.

즉, mcrypt_encrypt함수를 통해 php의 양방향 암호화를 진행할 수 있는 모듈입니다

 


이 기능은 PHP 7.1.0에서 더 이상 사용되지 않으며 PHP 7.2.0에서 제거되었습니다.
이 기능의 대안으로 아래와 같은 것을 사용할 수 있습니다.
- Sodium (PHP 7.2.0 부터 사용가능)
- OpenSSL


 

들어가기전...

PHP를 소스(Source)로 설치한 경우 입니다.

PHP-5.3.9 버전을 기준으로 설명합니다.

PHP-5.3.9 압축파일을 /usr/local/src 폴더에서 풀어놓고 설치를 하였습니다.

/usr/local/src/php-5.3.29/ 입니다.

설치한 폴더 옵션인 prefix는 /usr/local/php 로 해뒀습니다.

/usr/local/php 에 설치가 되어 있습니다.

 

mongo.so 확장모듈을 설치하기 위해서는 pecl 툴을 사용합니다.

 


-- 설치된 폴더 이동

cd /usr/local/src/php-5.3.29/ext

 

-- /usr/local/php/bin/phpize 명령어 에러 발생!!

libmcrypt 라이브러리에서 mcrypt.h 가 없다는 에러가 발생하면서 컴파일이 안되는 경우 발생

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

 

[root@national-pension-contents mcrypt]# /usr/local/php/bin/phpize 
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions
[root@national-pension-contents mcrypt]# ./configure --with-php-config=/usr/local/php/bin/php-config 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-zts-20090626
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for mcrypt support... yes, shared
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

 

-- Please reinstall libmcrypt. 발생시 libmcrypt  라이브러리 설치

1. yum 설치 방법 

# yum list php-mcrypt

# yum install php-mcrypt

 

 

2. mcrypt 모듈 다운로드 소스 설치 방법

가. 소스 다운로드 https://ko.osdn.net/projects/sfnet_mcrypt/downloads/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/

 

나. 설치하기 
# tar zxf libmcrypt-2.5.8.tar.gz 
# cd libmcrypt-2.5.8/

#  ./configure --prefix=/usr/local/
# make && make check && make install

 

libmcrypt-2.5.8.tar.gz  libssh2-1.8.1.tar.gz    
[root@national-pension-contents src]# tar zxf libmcrypt-2.5.8.tar.gz 
[root@national-pension-contents src]# cd libmcrypt-2.5.8/
[root@national-pension-contents libmcrypt-2.5.8]# ls
acinclude.m4    buildconf     config.log     COPYING.LIB  install-sh      libmcrypt.spec.in  Makefile.in    README
aclocal.m4      ChangeLog     config.status  depcomp      KNOWN-BUGS      libtool            missing        src
AUTHORS         config.guess  config.sub     doc          lib             ltmain.sh          mkinstalldirs  stamp-h1
autom4te.cache  config.h      configure      include      libltdl         Makefile           modules        THANKS
autoscan.log    config.h.in   configure.in   INSTALL      libmcrypt.spec  Makefile.am        NEWS           TODO
[root@national-pension-contents libmcrypt-2.5.8]# ./configure --prefix=/usr/local/


..............

*** Dynamic loading has been disabled
checking which algorithms to include into library... cbc cfb ctr ecb ncfb nofb ofb stream threeway cast-128 gost rijndael-128 safer-sk64 twofish  arcfour cast-256 loki97 rijndael-192 saferplus wake  blowfish-compat des rijndael-256 serpent xtea  blowfish enigma rc2 safer-sk128 tripledes
checking for dirent.h that defines DIR... yes
checking for library containing opendir... none required

..............


config.status: creating modules/Makefile
config.status: creating modules/modes/Makefile
config.status: creating modules/algorithms/Makefile
config.status: creating lib/libmcrypt-config
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing default-1 commands




[root@national-pension-contents libmcrypt-2.5.8]# make && make check && make install


............



/bin/install -c .libs/libmcrypt.lai /usr/local//lib/libmcrypt.la
PATH="$PATH:/sbin" ldconfig -n /usr/local//lib
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local//lib

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------
test -z "/usr/local//share/aclocal" || mkdir -p -- "/usr/local//share/aclocal"
 /bin/install -c -m 644 'libmcrypt.m4' '/usr/local//share/aclocal/libmcrypt.m4'
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/lib'
make[1]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/lib'
Making install in src
make[1]: Entering directory `/usr/local/src/libmcrypt-2.5.8/src'
make[2]: Entering directory `/usr/local/src/libmcrypt-2.5.8/src'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/src'
make[1]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/src'
Making install in doc
make[1]: Entering directory `/usr/local/src/libmcrypt-2.5.8/doc'
make[2]: Entering directory `/usr/local/src/libmcrypt-2.5.8/doc'
make[2]: Nothing to be done for `install-exec-am'.
test -z "/usr/local//man/man3" || mkdir -p -- "/usr/local//man/man3"
 /bin/install -c -m 644 './mcrypt.3' '/usr/local//man/man3/mcrypt.3'
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/doc'
make[1]: Leaving directory `/usr/local/src/libmcrypt-2.5.8/doc'
make[1]: Entering directory `/usr/local/src/libmcrypt-2.5.8'
make[2]: Entering directory `/usr/local/src/libmcrypt-2.5.8'
make[2]: Nothing to be done for `install-exec-am'.
make[2]: Nothing to be done for `install-data-am'.
make[2]: Leaving directory `/usr/local/src/libmcrypt-2.5.8'
make[1]: Leaving directory `/usr/local/src/libmcrypt-2.5.8'

 

 

-- ./configure --with-php-config=/usr/local/php/bin/php-config  재실행

#./configure --with-php-config=/usr/local/php/bin/php-config

# make && make install

 

[root@national-pension-contents libmcrypt-2.5.8]# ls
acinclude.m4    buildconf     config.log     COPYING.LIB  install-sh      libmcrypt.spec.in  Makefile.in    README
aclocal.m4      ChangeLog     config.status  depcomp      KNOWN-BUGS      libtool            missing        src
AUTHORS         config.guess  config.sub     doc          lib             ltmain.sh          mkinstalldirs  stamp-h1
autom4te.cache  config.h      configure      include      libltdl         Makefile           modules        THANKS
autoscan.log    config.h.in   configure.in   INSTALL      libmcrypt.spec  Makefile.am        NEWS           TODO
[root@national-pension-contents libmcrypt-2.5.8]# pwd
/usr/local/src/libmcrypt-2.5.8
[root@national-pension-contents libmcrypt-2.5.8]# cd ../php-5.3.29/ext/mcrypt/
[root@national-pension-contents mcrypt]# ./configure --with-php-config=/usr/local/php/bin/php-config 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-zts-20090626
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking for mcrypt support... yes, shared
checking for libmcrypt version... >= 2.5.6
checking for mcrypt_module_open in -lmcrypt... no
checking for mcrypt_module_open in -lmcrypt... yes
checking for ld used by cc... /bin/ld
checking if the linker (/bin/ld) is GNU ld... yes
checking for /bin/ld option to reload object files... -r
checking for BSD-compatible nm... /bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
[root@national-pension-contents mcrypt]# make && make install
/bin/sh /usr/local/src/php-5.3.29/ext/mcrypt/libtool --mode=compile cc  -I. -I/usr/local/src/php-5.3.29/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/mcrypt/include -I/usr/local/src/php-5.3.29/ext/mcrypt/main -I/usr/local/src/php-5.3.29/ext/mcrypt -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-5.3.29/ext/mcrypt/mcrypt.c -o mcrypt.lo 
mkdir .libs
 cc -I. -I/usr/local/src/php-5.3.29/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/mcrypt/include -I/usr/local/src/php-5.3.29/ext/mcrypt/main -I/usr/local/src/php-5.3.29/ext/mcrypt -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-5.3.29/ext/mcrypt/mcrypt.c  -fPIC -DPIC -o .libs/mcrypt.o
/bin/sh /usr/local/src/php-5.3.29/ext/mcrypt/libtool --mode=compile cc  -I. -I/usr/local/src/php-5.3.29/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/mcrypt/include -I/usr/local/src/php-5.3.29/ext/mcrypt/main -I/usr/local/src/php-5.3.29/ext/mcrypt -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-5.3.29/ext/mcrypt/mcrypt_filter.c -o mcrypt_filter.lo 
 cc -I. -I/usr/local/src/php-5.3.29/ext/mcrypt -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/mcrypt/include -I/usr/local/src/php-5.3.29/ext/mcrypt/main -I/usr/local/src/php-5.3.29/ext/mcrypt -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-5.3.29/ext/mcrypt/mcrypt_filter.c  -fPIC -DPIC -o .libs/mcrypt_filter.o
/usr/local/src/php-5.3.29/ext/mcrypt/mcrypt_filter.c: In function ‘php_mcrypt_filter_create’:
/usr/local/src/php-5.3.29/ext/mcrypt/mcrypt_filter.c:210:2: warning: passing argument 1 of ‘mcrypt_module_open’ discards ‘const’ qualifier from pointer target type [enabled by default]
  mcrypt_module = mcrypt_module_open(cipher, algo_dir, mode, mode_dir);
  ^
In file included from /usr/local/include/mcrypt.h:4:0,
                 from /usr/local/src/php-5.3.29/ext/mcrypt/mcrypt_filter.c:25:
/usr/local/include/mutils/mcrypt.h:38:9: note: expected ‘char *’ but argument is of type ‘const char *’
  MCRYPT mcrypt_module_open(char *algorithm,
         ^
/bin/sh /usr/local/src/php-5.3.29/ext/mcrypt/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/mcrypt/include -I/usr/local/src/php-5.3.29/ext/mcrypt/main -I/usr/local/src/php-5.3.29/ext/mcrypt -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/usr/local/include  -DHAVE_CONFIG_H  -g -O2   -o mcrypt.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-5.3.29/ext/mcrypt/modules  mcrypt.lo mcrypt_filter.lo -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lmcrypt
cc -shared  .libs/mcrypt.o .libs/mcrypt_filter.o  -Wl,--rpath -Wl,/usr/local//lib -Wl,--rpath -Wl,/usr/local//lib -L/usr/local/lib /usr/local//lib/libmcrypt.so  -Wl,-rpath -Wl,/usr/local/lib -Wl,-soname -Wl,mcrypt.so -o .libs/mcrypt.so
creating mcrypt.la
(cd .libs && rm -f mcrypt.la && ln -s ../mcrypt.la mcrypt.la)
/bin/sh /usr/local/src/php-5.3.29/ext/mcrypt/libtool --mode=install cp ./mcrypt.la /usr/local/src/php-5.3.29/ext/mcrypt/modules
cp ./.libs/mcrypt.so /usr/local/src/php-5.3.29/ext/mcrypt/modules/mcrypt.so
cp ./.libs/mcrypt.lai /usr/local/src/php-5.3.29/ext/mcrypt/modules/mcrypt.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/php-5.3.29/ext/mcrypt/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/php-5.3.29/ext/mcrypt/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20090626/

 

'/usr/local/php/lib/php/extensions/no-debug-zts-20090626/'에 보시면 mcrypt.so 파일이 보일 겁니다.

[root@national-pension-contents mcrypt]# ll  /usr/local/php/lib/php/extensions/no-debug-zts-20090626/
total 2728
-rwxr-xr-x 1 root root  159329 Feb 28 15:26 mcrypt.so
-rwxr-xr-x 1 root root 1949145 Feb 28 14:37 mongo.so
-rwxr-xr-x 1 root root  107970 Feb 28 14:36 pcntl.so
-rwxr-xr-x 1 root root  570358 Feb 28 14:56 zip.so
[root@national-pension-contents mcrypt]# 

 

그냥 아래 내용을 긁어서 사용하세요.

# libmcrypt 소스 파일 설치 

wget https://ko.osdn.net/projects/sfnet_mcrypt/downloads/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/
tar zxf libmcrypt-2.5.8.tar.gz 
cd libmcrypt-2.5.8/
./configure --prefix=/usr/local/
make && make check && make install


#mcrypts.so확장 모듈 설치

cd /usr/local/src/php-5.3.29/ext/mcrypt
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
728x90

pcntl.so 확장 모듈 추가하기

 

 

pcntl 은 PHP가 지원하는 프로세스 제어 함수로 Unix 형식의 프로세스 생성, 프로세스 실행, 신호 처리, 프로세스 종료 기능을 구현하고 있습니다. 

웹 서버 환경에서 프로세스 제어를 사용하지 않아야 하며 웹 서버 환경에서 프로세스 제어 기능을 사용하면 예기치 않은 결과가 발생할 수 있습니다.

현재 PCNTL는 신호 처리 콜백 메커니즘으로 ticks를 사용하고 있고,
"user ticks"를 사용하는 것과 같은 것입니다.

declare()를 사용하여 프로그램에서 콜백의 발생을 허용하는 위치를 지정해야합니다.

따라서 비동기 이벤트를 처리하는 오버 헤드를 최소화하는 것이 가능합니다.

이전에는 pcntl를 사용하여 PHP를 컴파일하면 pcntl의 사용 여부에 관계없이 항상이 오버 헤드의 피해를 입을 수 있습니다.


 

들어가기전...

PHP를 소스(Source)로 설치한 경우 입니다.

PHP-5.3.9 버전을 기준으로 설명합니다.

PHP-5.3.9 압축파일을 /usr/local/src 폴더에서 풀어놓고 설치를 하였습니다.

/usr/local/src/php-5.3.29/ 입니다.

설치한 폴더 옵션인 prefix는 /usr/local/php 로 해뒀습니다.

/usr/local/php 에 설치가 되어 있습니다.


 

-- PHP 소스 설치 폴더로 이동 ..

#cd /usr/local/src/php-소스폴더/ext

 

-- phpize 로 확장모듈 configure 파일 생성

# /usr/local/php/bin/phpize 

[root@national-pension-contents php-5.3.29]# cd ext/
[root@national-pension-contents ext]# ls
bcmath      dom                 ftp        intl      mysqli   pdo_dblib     phar        simplexml  standard   xml
bz2         enchant             gd         json      mysqlnd  pdo_firebird  posix       skeleton   sybase_ct  xmlreader
calendar    ereg                gettext    ldap      oci8     pdo_mysql     pspell      snmp       sysvmsg    xmlrpc
com_dotnet  exif                gmp        libxml    odbc     pdo_oci       readline    soap       sysvsem    xmlwriter
ctype       ext_skel            hash       mbstring  openssl  pdo_odbc      recode      sockets    sysvshm    xsl
curl        ext_skel_win32.php  iconv      mcrypt    pcntl    pdo_pgsql     reflection  spl        tidy       zip
date        fileinfo            imap       mssql     pcre     pdo_sqlite    session     sqlite     tokenizer  zlib
dba         filter              interbase  mysql     pdo      pgsql         shmop       sqlite3    wddx
[root@national-pension-contents ext]# 
[root@national-pension-contents ext]# cd pcntl/
[root@national-pension-contents pcntl]# ls
config.m4  CREDITS  package.xml  pcntl.c  php_pcntl.h  php_signal.c  php_signal.h  README  test-pcntl.php  tests

[root@national-pension-contents pcntl]# 
[root@national-pension-contents pcntl]#  /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions

[root@national-pension-contents pcntl]# ls
acinclude.m4    config.guess  configure     ltmain.sh        package.xml   php_signal.h    tests
aclocal.m4      config.h.in   configure.in  Makefile.global  pcntl.c       README
autom4te.cache  config.m4     CREDITS       missing          php_pcntl.h   run-tests.php
build           config.sub    install-sh    mkinstalldirs    php_signal.c  test-pcntl.php


[root@national-pension-contents pcntl]# ./configure 
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: error: Cannot find php-config. Please use --with-php-config=PATH

 

-- configure 실행시 에러 발생

#./configure 

.......

Please use --with-php-config=PATH

 

-- PHP 소스를 /usr/local/php에 설치하셨다면 아래와 같이 ...

# ./configure --with-php-config=/usr/local/php/bin/php-config

[root@national-pension-contents pcntl]# ./configure --with-php-config=/usr/local/php/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-zts-20090626
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable pcntl support... yes, shared
checking for fork... yes
checking for waitpid... yes
checking for sigaction... yes
checking for getpriority... yes
checking for setpriority... yes
checking for wait3... yes
checking for sigprocmask... yes
checking for sigwaitinfo... yes
checking for sigtimedwait... yes
checking for ld used by cc... /bin/ld
checking if the linker (/bin/ld) is GNU ld... yes
checking for /bin/ld option to reload object files... -r
checking for BSD-compatible nm... /bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

 

-- make && make install 하기

# make && make install

[root@national-pension-contents pcntl]# make && make install
/bin/sh /usr/local/src/php-5.3.29/ext/pcntl/libtool --mode=compile cc  -I. -I/usr/local/src/php-5.3.29/ext/pcntl -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/pcntl/include -I/usr/local/src/php-5.3.29/ext/pcntl/main -I/usr/local/src/php-5.3.29/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-5.3.29/ext/pcntl/pcntl.c -o pcntl.lo 
mkdir .libs
 cc -I. -I/usr/local/src/php-5.3.29/ext/pcntl -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/pcntl/include -I/usr/local/src/php-5.3.29/ext/pcntl/main -I/usr/local/src/php-5.3.29/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-5.3.29/ext/pcntl/pcntl.c  -fPIC -DPIC -o .libs/pcntl.o
/bin/sh /usr/local/src/php-5.3.29/ext/pcntl/libtool --mode=compile cc  -I. -I/usr/local/src/php-5.3.29/ext/pcntl -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/pcntl/include -I/usr/local/src/php-5.3.29/ext/pcntl/main -I/usr/local/src/php-5.3.29/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /usr/local/src/php-5.3.29/ext/pcntl/php_signal.c -o php_signal.lo 
 cc -I. -I/usr/local/src/php-5.3.29/ext/pcntl -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/pcntl/include -I/usr/local/src/php-5.3.29/ext/pcntl/main -I/usr/local/src/php-5.3.29/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /usr/local/src/php-5.3.29/ext/pcntl/php_signal.c  -fPIC -DPIC -o .libs/php_signal.o
/bin/sh /usr/local/src/php-5.3.29/ext/pcntl/libtool --mode=link cc -DPHP_ATOM_INC -I/usr/local/src/php-5.3.29/ext/pcntl/include -I/usr/local/src/php-5.3.29/ext/pcntl/main -I/usr/local/src/php-5.3.29/ext/pcntl -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -o pcntl.la -export-dynamic -avoid-version -prefer-pic -module -rpath /usr/local/src/php-5.3.29/ext/pcntl/modules  pcntl.lo php_signal.lo 
cc -shared  .libs/pcntl.o .libs/php_signal.o   -Wl,-soname -Wl,pcntl.so -o .libs/pcntl.so
creating pcntl.la
(cd .libs && rm -f pcntl.la && ln -s ../pcntl.la pcntl.la)
/bin/sh /usr/local/src/php-5.3.29/ext/pcntl/libtool --mode=install cp ./pcntl.la /usr/local/src/php-5.3.29/ext/pcntl/modules
cp ./.libs/pcntl.so /usr/local/src/php-5.3.29/ext/pcntl/modules/pcntl.so
cp ./.libs/pcntl.lai /usr/local/src/php-5.3.29/ext/pcntl/modules/pcntl.la
PATH="$PATH:/sbin" ldconfig -n /usr/local/src/php-5.3.29/ext/pcntl/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /usr/local/src/php-5.3.29/ext/pcntl/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20090626/

아래의 폴더에 pcntl.so 파일이 있습니다.

/usr/local/php/lib/php/extensions/no-debug-zts-20090626/

 

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20090626/

 

 


[root@national-pension-contents zip]# cd /usr/local/php/lib/php/extensions/no-debug-zts-20090626/

[root@national-pension-contents no-debug-zts-20090626]# ll

total 2572

-rw-r--r-- 1 root root 1949145 Feb 28 14:37 mongo.so

-rwxr-xr-x 1 root root  107970 Feb 28 14:36 pcntl.so

-rwxr-xr-x 1 root root  570358 Feb 28 14:56 zip.so

 

혹시 실행권한이 없다면 chmod 755로 실행권을 주시길 바랍니다.

[root@national-pension-contents no-debug-zts-20090626]# chmod 755 *

[root@national-pension-contents no-debug-zts-20090626]# ll

total 2572

-rwxr-xr-x 1 root root 1949145 Feb 28 14:37 mongo.so

-rwxr-xr-x 1 root root  107970 Feb 28 14:36 pcntl.so

-rwxr-xr-x 1 root root  570358 Feb 28 14:56 zip.so

 

 

아래는 해당 extension할 모듈을 설치하기 위한 스크립트 입니다.

/usr/local/php/bin/phpize 
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd /usr/local/php/lib/php/extensions/no-debug-zts-20090626/
chmod 755 *

 

728x90

mongo.so 확장 모듈 추가하기

 

mongo.so 는 php에서 mongoDB를 커넥트 해서 사용하기 위한 모듈입니다.

mongoDB를 사용하겠다고 하시면 mongo.so 확장 모듈을 설치하셔야 합니다.

 

들어가기전...

PHP를 소스(Source)로 설치한 경우 입니다.

PHP-5.3.9 버전을 기준으로 설명합니다.

PHP-5.3.9 압축파일을 /usr/local/src 폴더에서 풀어놓고 설치를 하였습니다.

/usr/local/src/php-5.3.29/ 입니다.

설치한 폴더 옵션인 prefix는 /usr/local/php 로 해뒀습니다.

/usr/local/php 에 설치가 되어 있습니다.

 

mongo.so 확장모듈을 설치하기 위해서는 pecl 툴을 사용합니다.

 


-- 설치된 폴더 이동

cd /usr/local/php/bin/

[root@national-pension-contents bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-config  phpize

 

-- pecl install mongo 명령어로 mongo.so 확장모듈 설치

[root@national-pension-contents bin]# pecl install mongo
-bash: pecl: command not found
[root@national-pension-contents bin]# ./pecl install mongo

[root@national-pension-contents pcntl]# cd /usr/local/php/bin/
[root@national-pension-contents bin]# ls
pear  peardev  pecl  phar  phar.phar  php  php-config  phpize


[root@national-pension-contents bin]#  pecl install mongo
-bash: pecl: command not found

[root@national-pension-contents bin]# ./pecl install mongo
WARNING: "pecl/mongo" is deprecated in favor of "channel:///mongodb"
downloading mongo-1.6.16.tgz ...
Starting to download mongo-1.6.16.tgz (210,341 bytes)
.............................................done: 210,341 bytes
118 source files, building
running: phpize
Configuring for:
PHP Api Version:         20090626
Zend Module Api No:      20090626
Zend Extension Api No:   220090626
configure.in:3: warning: prefer named diversions
configure.in:3: warning: prefer named diversions
Build with Cyrus SASL (MongoDB Enterprise Authentication) support? [no] : 
building in /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16
running: /tmp/pear/temp/mongo/configure --with-mongo-sasl=no
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for PHP prefix... /usr/local/php
checking for PHP includes... -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/php/lib/php/extensions/no-debug-zts-20090626
checking for PHP installed headers prefix... /usr/local/php/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... gawk
checking whether to enable Mongo extension... yes, shared
checking Build with OpenSSL support... yes
checking for pkg-config... /bin/pkg-config
checking whether byte ordering is bigendian... no
checking whether to include code coverage symbols... no
checking Build with Cyrus SASL support... no
checking for ld used by cc... /bin/ld
checking if the linker (/bin/ld) is GNU ld... yes
checking for /bin/ld option to reload object files... -r
checking for BSD-compatible nm... /bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 1572864
checking command to parse /bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... no
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h
running: make
/bin/sh /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/libtool --mode=compile cc -I./util -I. -I/tmp/pear/temp/mongo -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/include -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/main -I/tmp/pear/temp/mongo -I/usr/local/php/include/php -I/usr/local/php/include/php/main -I/usr/local/php/include/php/TSRM -I/usr/local/php/include/php/Zend -I/usr/local/php/include/php/ext -I/usr/local/php/include/php/ext/date/lib -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/api -I/tmp/pear/temp/mongo/api -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/util -I/tmp/pear/temp/mongo/util -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/exceptions -I/tmp/pear/temp/mongo/exceptions -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/gridfs -I/tmp/pear/temp/mongo/gridfs -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/types -I/tmp/pear/temp/mongo/types -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/batch -I/tmp/pear/temp/mongo/batch -I/tmp/pear/te
mp/pear-build-root6il05e/mongo-1.6.16/contrib -I/tmp/pear/temp/mongo/contrib -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/mcon -I/tmp/pear/temp/mongo/mcon -I/tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/mcon/contrib -I/tmp/pear/temp/mongo/mcon/contrib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/mongo/php_mongo.c -o php_mongo.lo
mkdir .libs


................



(cd .libs && rm -f mongo.la && ln -s ../mongo.la mongo.la)
/bin/sh /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/libtool --mode=install cp ./mongo.la /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/modules
cp ./.libs/mongo.so /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/modules/mongo.so
cp ./.libs/mongo.lai /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/modules/mongo.la
PATH="$PATH:/sbin" ldconfig -n /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /tmp/pear/temp/pear-build-root6il05e/mongo-1.6.16/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag
   - have your system administrator add LIBDIR to `/etc/ld.so.conf'

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16" install
Installing shared extensions:     /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib/php/extensions/no-debug-zts-20090626/
running: find "/tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16" | xargs ls -dils
  4553477    0 drwxr-xr-x 3 root root      16 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16
  4553502    0 drwxr-xr-x 3 root root      18 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr
 76481663    0 drwxr-xr-x 3 root root      16 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local
140750308    0 drwxr-xr-x 3 root root      16 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php
209205010    0 drwxr-xr-x 3 root root      16 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib
  4553503    0 drwxr-xr-x 3 root root      23 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib/php
 76481664    0 drwxr-xr-x 3 root root      34 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib/php/extensions
140750309    0 drwxr-xr-x 2 root root      21 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib/php/extensions/no-debug-zts-20090626
140750311 1904 -rwxr-xr-x 1 root root 1949145 Feb 28 14:37 /tmp/pear/temp/pear-build-root6il05e/install-mongo-1.6.16/usr/local/php/lib/php/extensions/no-debug-zts-20090626/mongo.so

Build process completed successfully
Installing '/usr/local/php/lib/php/extensions/no-debug-zts-20090626/mongo.so'
install ok: channel://pecl.php.net/mongo-1.6.16
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini

 

-- 성공적으로 추가되었다면 

'/usr/local/php/lib/php/extensions/no-debug-zts-20090626/mongo.so'에 설치되어 있습니다.

그리고 php.ini 파일에 "extension=mongo.so" 을 추가해주면 됩니다.

Build process completed successfully
Installing '/usr/local/php/lib/php/extensions/no-debug-zts-20090626/mongo.so'
install ok: channel://pecl.php.net/mongo-1.6.16
configuration option "php_ini" is not set to php.ini location
You should add "extension=mongo.so" to php.ini

 

그냥 아래 내용을 긁어서 사용하세요.

cd /usr/local/php/bin/

ls

./pecl install mongo

 

728x90

ORM 

데이터베이스 시스템에 저장된 데이터를 객체로 표현하기 위한 변환하는 것을 말합니다.

그 반대로, 객체에 저장된 데이터를 데이터베이스 시스템에 저장하기 위해 데이터를 변환하는 것을 말합니다.

 

 

엘로퀸트 ORM

라라벨이 제공하는ORM 구현체의 이름입니다.

라라벨에서 데이터베이스의 데이터를 객체로 변환해 놓은 것입니다.

데이터 모델 정도로 이해하면 편할 거 같네요.

 


1. MYSQL에 authors, posts 테이블을 만듭니다.

create table authors(
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(20) NOT NULL default '',
email varchar(255) NOT NULL default '',
pwd varchar(60) NOT NULL default '',
profiles text NOT NULL,
regDate datetime NOT NULL
)ENGINE=InnoDB DEFAULT Charset=UTF8 Collate=utf8_unicode_ci;

 

create table posts(
	id int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	title varchar(255) NOT NULL default '',
	contents TEXT NOT NULL,
	regDate datetime NOT NULL
)ENGINE=InnoDB DEFAULT Charset=UTF8 Collate=utf8_unicode_ci;

 

2. tinker 를 이용해서 authors, posts 테이블에 insert 하기

 

 

$ php artisan tinker

>>> DB::insert('insert into authors(name, email,pwd,profiles, regDate)values(?,?,?,?, now())', ['한치로', 'hanchiro@naver.com','password','']);

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['hello chiro','고마워 tinker 야']);

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['잘지내고 있나요?','잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요']);

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['how do you today?','how do you today? those day I have been study english']);

 

3. 모델 만들기 - php artisan make:model

php artisan make:model Post

php artisan make:model Author

hanui-MacBook-Pro:NationalPension hanchiro$ php artisan make:model Post
Model created successfully.
hanui-MacBook-Pro:NationalPension hanchiro$ php artisan make:model Author
Model created successfully.
hanui-MacBook-Pro:NationalPension hanchiro$ 

 

모델을 만들게 되면 laravel프로젝트안에 Author.php 와 Post.php 라는 파일이 만들어 집니다.

 

 

 

4. DB Tablre 과 객체 연결하기

Author.php, Post.php  파일에서 각각 

protected $table = '테이블명'; 

을 추가해줍니다.

5. php artisan tinker에서 객체 실행해 보기

App\Author::get();
App\Post::get();

hanui-MacBook-Pro:NationalPension hanchiro$ php artisan tinker
Psy Shell v0.9.12 (PHP 7.1.1 — cli) by Justin Hileman
>>> 
>>> 
>>> App\Author::get();
=> Illuminate\Database\Eloquent\Collection {#2915
     all: [
       App\Author {#2916
         id: 1,
         name: "한치로",
         email: "hanchiro@naver.com",
         pwd: "password",
         profiles: "",
         regDate: "2020-02-12 17:32:05",
       },
     ],
   }
>>> App\Post::get();
=> Illuminate\Database\Eloquent\Collection {#2919
     all: [
       App\Post {#2918
         id: 1,
         title: "hello chiro",
         contents: "고마워 tinker 야",
         regDate: "2020-02-12 16:12:02",
       },
       App\Post {#2917
         id: 2,
         title: "잘지내고 있나요?",
         contents: "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",
         regDate: "2020-02-12 16:12:39",
       },
       App\Post {#2914
         id: 3,
         title: "how do you today?",
         contents: "how do you today? those day I have been study english",
         regDate: "2020-02-12 16:14:16",
       },
     ],
   }
>>> 

 

객체와 DB 가 제대로 연결되어 나타나네요..ㅋㅋㅋ

 


6. php artisan tinker 으로 새로운 row  레코드 만들기

>>> $author = new App\Author;

>>> $author->get();

>>> $author->save()

hanui-MacBook-Pro:NationalPension hanchiro$ php artisan tinker
Psy Shell v0.9.12 (PHP 7.1.1 — cli) by Justin Hileman
>>> $author = new App\Author;
=> App\Author {#2903}
>>> $author->get();
=> Illuminate\Database\Eloquent\Collection {#2904
     all: [
       App\Author {#2911
         id: 1,
         name: "한치로",
         email: "hanchiro@xxx.com",
         pwd: "password",
         profiles: "",
         regDate: "2020-02-12 17:32:05",
       },
     ],
   }
>>> $author->email
=> null
>>> $author->email ='hanchiro@xxx.com';
=> "hanchiro@xxx.com"
>>> $author->password='111222';
=> "111222"
>>> $author->save()

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password' in 'field list' (SQL: insert into `authors` (`email`, `password`, ...

로 시작하면서 password 라는 필드가 없다고 에러를 내네요.

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password' in 'field list' (SQL: insert into `authors` (`email`, `password`, `updated_at`, `created_at`) values (hanchiro@xxx.com, 111222, 2020-02-13 01:17:22, 2020-02-13 01:17:22))'

 

6-1. public $timestamps = false;

->save() 를 사용하게 되면 호출에서 예외가 발생합니다.

>>> $author = new App\Author
=> App\Author {#2909}
>>> $author->email ='hanchiro@xxx.com';
=> "hanchiro@xxx.com"
>>> $author->pwd='111222';
=> "111222"
>>> $author->save()
Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'updated_at' in 'field list' (SQL: insert into `authors` (`email`, `pwd`, `updated_at`, `created_at`) values (hanchiro@xxx.com, 111222, 2020-02-13 01:24:47, 2020-02-13 01:24:47))'

 

이게 뭐냐면 엘로퀸트는 모든 테이블에 update_at와 create_at라는 datetime 필드를 자동으로 만들어 줍니다.

그래서 우리가 tinker 에서 row 정보를 만들어서 insert하고자 할대 update_at, create_at필드를 자동으로 추가해서 insert 구문을 만들어요.

그런데 실제 우리 MySQL의 Authors 테이블에는 이런 update_at, create_at 필드가 없죠.

그래서 에러가 나는 겁니다.

이를 해결 하기 위해서는 아래와 같이  public $timestamps = false; 를 model을 상속받은 Author 모델에 override 해줍니다.

// Model extends를 하면 datetime의 created_at, 와 updated_at 가 자동 생성되어진다.
   // 이를 없애기 위해서 아래의 옵션을 준다.
   // 별도의 table에 등록일자, 수정일자를 두고 있다면 아래와 같이 옵션을 주자.
   public $timestamps = false;

 

App/Author.php 파일에 public $timestamps = false;  추가

 

 

결국 메모리에 남아 있기 때문에 새로 $author = new App\Author;  부터 다시 만들었습니다.

여러번 실수를 하게 되었네요.

>>> $author = new App\Author
=> App\Author {#2903}
>>> $author->email ='hanchiro@xxx.com';
=> "hanchiro@xxx.com"
>>> $author->pwd='111222';
=> "111222"
>>> $author->save()
Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'profiles' doesn't have a default value (SQL: insert into `authors` (`email`, `pwd`) values (hanchiro@xxx.com, 111222))'
>>> $author->profiles = '프로필';
=> "프로필"
>>> $author->save()
Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'regDate' doesn't have a default value (SQL: insert into `authors` (`email`, `pwd`, `profiles`) values (hanchiro@xxx.com, 111222, 프로필))'
>>> $author->re;
readme.md  resources/ 
>>> $author->regDate = now();
=> Illuminate\Support\Carbon @1581557248 {#2916
     date: 2020-02-13 01:27:28.535030 UTC (+00:00),
   }
>>> $author->save()
=> true

 

>>> $author = new App\Author
=> App\Author {#2903}
>>> $author->email ='hanchiro@xxx.com';
=> "hanchiro@xxx.com"
>>> $author->pwd='111222';
=> "111222"
>>> $author->profiles = '프로필';
=> "프로필"
>>> $author->regDate = now();
=> Illuminate\Support\Carbon @1581557248 {#2916
     date: 2020-02-13 01:27:28.535030 UTC (+00:00),
   }
>>> $author->save()
=> true

 

실제 mysql  DB에 등록되었는지 확인해보세요.

이런 전 이름을 안넣었네요 ^^;;



7. App\Author::create / protected $fillable  / protected $guarded

hanui-MacBook-Pro:NationalPension hanchiro$ php artisan tinker
Psy Shell v0.9.12 (PHP 7.1.1 — cli) by Justin Hileman
>>> App\Author::create([
... 'email'=>'hanchiro@zzz.com',
... 'profiles'=>'프로필',
... 'name'=>'에버런'
... 'pwd'=>bcrypt('password'),
PHP Parse error: Syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ')' or ']' on line 5
>>> App\Author::create([
'email'=>'hanchiro@zzz.com',
'profiles'=>'프로필',
'name'=>'에버런',
'pwd'=>bcrypt('password'),
... ]);
Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'profiles' doesn't have a default value (SQL: insert into `authors` (`email`, `pwd`) values (hanchiro@zzz.com, $2y$10$qIfbUYenMqUPxERQCjEkTexZ2sIbCRDBCboacN1qbR89MlzTZquyO))'

 

엘로퀸트는 데이터베이스를 대량할당을 할때 필드마다 특성이 있을 수 있기 때문에 보호 장치를 2가지 뒀습니다.

1. $fillable 프로퍼티로 허용할 필드를 배열로 넣어주면 됩니다.

protected $fillable = [];
2. $guarded 프로퍼티로 금지할 필드를 배열로 넣어 주면 됩니다.
protected $guarded = [];

 

 

그리고 나서 다시 App\Author::create([]); 로 row 를 저장하니 제대로 등록이 되네요.

>>> App\Author::create([
... 'name'=>'에버런',
... 'email'=>'hanchiro@zzz.com',
... 'profiles'=>'프로필',
... 'pwd'=>bcrypt('password'), 
... 'regDate'=>now()
... ]);
=> App\Author {#2912
     email: "hanchiro@zzz.com",
     profiles: "프로필",
     pwd: "$2y$10$nFAC6nPoY6IV.gCU579.fO12d.PWFFHSr037H0J3EigJ9ispgrd4W",
     regDate: Illuminate\Support\Carbon @1581557855 {#2921
       date: 2020-02-13 01:37:35.643235 UTC (+00:00),
     },
     id: 3,
   }
>>> App\Author::get()
=> Illuminate\Database\Eloquent\Collection {#2899
     all: [
       App\Author {#2901
         id: 1,
         name: "한치로",
         email: "hanchiro@yyy.com",
         pwd: "password",
         profiles: "",
         regDate: "2020-02-12 17:32:05",
       },
       App\Author {#2900
         id: 2,
         name: "",
         email: "hanchiro@xxx.com",
         pwd: "111222",
         profiles: "프로필",
         regDate: "2020-02-13 01:27:28",
       },
       App\Author {#2902
         id: 3,
         name: "",
         email: "hanchiro@zzz.com",
         pwd: "$2y$10$nFAC6nPoY6IV.gCU579.fO12d.PWFFHSr037H0J3EigJ9ispgrd4W",
         profiles: "프로필",
         regDate: "2020-02-13 01:37:35",
       },
     ],
   }
>>> 

 

728x90

라라벨의 기능중에서 DB관련 파사드 지원해 줍니다.

SQL 삽입 과 같은 악의적 공격 원천 차단하기 위해서 파사드를 사용합니다.

이를 이용해서 실제 DB에 데이터를 넣고 테스트를 할 수 있습니다.

그중에서 tinker의 사용법을 알아보겠습니다


1. Mysql 유저 생성 및 DB 생성하기 (mysql DB서버에 접속할 로그인 정보를 만든다고 생각하세요)

hanui-MacBook-Pro:NationalPension hanchiro$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.7.16 MySQL Community Server (GPL)



Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.



Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.



Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.



 

 

mysql > use mysql;
mysql > create database posts;
-- posts 라는 데이터베이스를 만들었습니다.

mysql > create USER '유저' IDENTIFIED BY '비밀번호';
-- 유저로 '유저' 라는 아이디를 만들어서 '비밀번호'와 함께 생성해줍니다.

mysql > grant all privileges on posts.* to '유저';
-- posts 로 시작하는 DB에 대해서 posts라는 데이터베이스 를 찾아서 '유저'에 대해 권한을 부여합니다.

mysql > flush privileges;
-- 해당 설정값이 mysql 에 적용이 되도록 해줍니다.

mysql > quit;
-- 나옵니다.

 

mysql > use mysql;
mysql > create database posts;
mysql > create USER 'postsID' IDENTIFIED BY 'postsPASSWORD';
mysql > grant all privileges on posts.* to 'postsID';
mysql > flush privileges;
mysql > quit;

 

생성한 DB명 : posts

생성한 USER아이디 : postsID

생성한 PASSWORD : postsPASSWORD

 

를 만들어 뒀습니다.(꼭 수정해서 mysql DB 를 만들어 쓰세요 ^^)

그리고 이 DB 로그인 정보는 꼭 기억해 두세요.

 

 

2. posts 테이블 만들기

mysql  서버에 접속해서 posts DB에 접속한 다음에  "use posts"  로 posts DB로 이동합니다.

hanui-MacBook-Pro:NationalPension hanchiro$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 15

Server version: 5.7.16 MySQL Community Server (GPL)



Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.



Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.



Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use posts

 

아래와 같이 posts  데이터베이스 안에 posts라는 테이블을 만들어 줍니다.

create table posts(
	id int(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
	title varchar(255) NOT NULL default '',
	contents TEXT NOT NULL,
	regDate datetime NOT NULL
)ENGINE=InnoDB DEFAULT Charset=UTF8 Collate=utf8_unicode_ci;

 

 


3. laravel 설정파일 .env 파일에 파란박스 부분에 DB 를 생성할때의 내용을 입력 해줍니다.

1. 번에서 생성한

생성한 DB명 : posts

생성한 USER아이디 : postsID

생성한 PASSWORD : postsPASSWORD

를 .env 파일에 똑같은 쌍으로 입력 해주세요

 

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=생성한 DB명
DB_USERNAME=생성한 USER아이디
DB_PASSWORD=생성한 PASSWORD

 

 

 

 


4. php artisan tinker 사용하기!! 

hanui-MacBook-Pro:NationalPension hanchiro$ php artisan tinker

Psy Shell v0.9.12 (PHP 7.1.1 — cli) by Justin Hileman

 

DB::insert

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['hello chiro','고마워 tinker 야']);

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['잘지내고 있나요?','잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요']);

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['how do you today?','how do you today? those day I have been study english']);

 

>>> DB::insert('insert into posts(title,contents,stDate)values(?,?,now()), ['hello chiro','고마워 tinker 야']);

PHP Parse error: Syntax error, unexpected T_STRING, expecting ')' on line 1

>>> DB::insert('insert into posts(title,contents,stDate)values(?,?,now()), ['hello chiro','고마워 tinker 야']');

PHP Parse error: Syntax error, unexpected T_STRING, expecting ')' on line 1

>>> DB::insert('insert into posts(title,contents,stDate)values(?,?,now())', ['hello chiro','고마워 tinker 야']);

Illuminate/Database/QueryException with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'stDate' in 'field list' (SQL: insert into posts(title,contents,stDate)values(hello chiro,고마워 tinker 야,now()))'


>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['hello chiro','고마워 tinker 야']);

=> true

>>> DB::table('posts')->get();

=> Illuminate\Support\Collection {#2910

     all: [

       {#2900

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

     ],

   }


>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['잘지내고 있나요?','잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요']);

=> true

>>> DB::insert('insert into posts(title,contents,regDate)values(?,?,now())', ['how do you today?','how do you today? those day I have been study english']);

=> true

>>> DB::table('posts')->get();

=> Illuminate\Support\Collection {#2914

     all: [

       {#2913

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

       {#2896

         +"id": 2,

         +"title": "잘지내고 있나요?",

         +"contents": "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",

         +"regDate": "2020-02-12 16:12:39",

       },

       {#2908

         +"id": 3,

         +"title": "how do you today?",

         +"contents": "how do you today? those day I have been study english",

         +"regDate": "2020-02-12 16:14:16",

       },

     ],

   }

 

DB::select

>>> $posts = DB::select('select * from posts');

>>> $posts[0]->title;

>>> $posts[1]->title;

>>> $posts[3]->title;

>>> $posts[2]->title;

>>> $posts = DB:select('select * from posts');

PHP Parse error: Syntax error, unexpected ':' on line 1

>>> $posts = DB::select('select * from posts');

=> [

     {#2915

       +"id": 1,

       +"title": "hello chiro",

       +"contents": "고마워 tinker 야",

       +"regDate": "2020-02-12 16:12:02",

     },

     {#2907

       +"id": 2,

       +"title": "잘지내고 있나요?",

       +"contents": "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",

       +"regDate": "2020-02-12 16:12:39",

     },

     {#2912

       +"id": 3,

       +"title": "how do you today?",

       +"contents": "how do you today? those day I have been study english",

       +"regDate": "2020-02-12 16:14:16",

     },

   ]

>>> $posts[0]->title;

=> "hello chiro"

>>> $posts[1]->title;

=> "잘지내고 있나요?"

>>> $posts[3]->title;

PHP Notice:  Undefined offset: 3 in Psy Shell code on line 1

>>> $posts[2]->title;

=> "how do you today?"

>>> $post = DB:selectOne('select * from posts');

PHP Parse error: Syntax error, unexpected ':' on line 1

 

DB::selectOne

>>> $post = DB::selectOne('select * from posts');

>>> $post = DB::selectOne('select * from posts');



=> {#2909

     +"id": 1,

     +"title": "hello chiro",

     +"contents": "고마워 tinker 야",

     +"regDate": "2020-02-12 16:12:02",

   }

>>> $post->title;

=> "hello chiro"

>>> 

 

DB::table('posts')->first();

>>> DB::table('posts')->last();

>>> DB::table('posts')->first();
=> {#2920
     +"id": 1,
     +"title": "hello chiro",
     +"contents": "고마워 tinker 야",
     +"regDate": "2020-02-12 16:12:02",
   }

 

DB::table('posts')->last(); 는 안되네요

>>> DB::table('posts')->last();

BadMethodCallException with message 'Call to undefined method Illuminate/Database/Query/Builder::last()'

 

 

 

 

>>> DB::table('posts')->find(); 는 안되네요

>>> DB::table('posts')->find();
TypeError: Too few arguments to function Illuminate/Database/Query/Builder::find(), 0 passed in Psy Shell code on line 1 and at least 1 expected

 

DB::table('posts')->find(2);

>>> DB::table('posts')->find(2);

=> {#2918

     +"id": 2,

     +"title": "잘지내고 있나요?",

     +"contents": "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",

     +"regDate": "2020-02-12 16:12:39",

   }

 

>>> DB::table('posts')->find(1,2); 안되요

>>> DB::table('posts')->find(1,2);

TypeError: Argument 1 passed to Illuminate/Database/Grammar::columnize() must be of the type array, integer given, called in /Users/hanchiro/dev/workspace_php/NationalPension/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 131

 

DB::table('posts')->find([1,2]); 이건 좀 이상하네요.

>>> DB::table('posts')->find([1,2]);

=> {#2914

     +"id": 1,

     +"title": "hello chiro",

     +"contents": "고마워 tinker 야",

     +"regDate": "2020-02-12 16:12:02",

   }

>>> DB::table('posts')->find([2,3]);

=> {#2920

     +"id": 2,

     +"title": "잘지내고 있나요?",

     +"contents": "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",

     +"regDate": "2020-02-12 16:12:39",

   }

 

DB::table('posts')->find([2]);

>>> DB::table('posts')->find([2]);

=> {#2900

     +"id": 2,

     +"title": "잘지내고 있나요?",

     +"contents": "잘 지내고 있나요? 전 요즈음 영어공부를 하고 있어요",

     +"regDate": "2020-02-12 16:12:39",

   }

 

DB::table('posts')->find([1-2]); --> null 이 나오네요

>>> DB::table('posts')->find([1-2]);

=> null

 

 

DB::table('posts')->where('id=1); 은 안되요

>>> DB::table('posts')->where('id=1);

PHP Parse error: Syntax error, unexpected T_ENCAPSED_AND_WHITESPACE on line 1

 

DB::table('posts')->where('id','=',1); 에서 ->get()을 해줘야 해요.

>>> DB::table('posts')->where('id','=',1);

=> Illuminate\Database\Query\Builder {#2924

     +connection: Illuminate\Database\MySqlConnection {#2904},

     +grammar: Illuminate\Database\Query\Grammars\MySqlGrammar {#2903},

     +processor: Illuminate\Database\Query\Processors\MySqlProcessor {#2902},

     +bindings: [

       "select" => [],

       "join" => [],

       "where" => [

         1,

       ],

       "having" => [],

       "order" => [],

       "union" => [],

     ],

     +aggregate: null,

     +columns: null,

     +distinct: false,

     +from: "posts",

     +joins: null,

     +wheres: [

       [

         "type" => "Basic",

         "column" => "id",

         "operator" => "=",

         "value" => 1,

         "boolean" => "and",

       ],

     ],

     +groups: null,

     +havings: null,

     +orders: null,

     +limit: null,

     +offset: null,

     +unions: null,

     +unionLimit: null,

     +unionOffset: null,

     +unionOrders: null,

     +lock: null,

     +operators: [

       "=",

       "<",

       ">",

       "<=",

       ">=",

       "<>",

       "!=",

       "<=>",

       "like",

       "like binary",

       "not like",

       "ilike",

       "&",

       "|",

       "^",

       "<<",

       ">>",

       "rlike",

       "regexp",

       "not regexp",

       "~",

       "~*",

       "!~",

       "!~*",

       "similar to",

       "not similar to",

       "not ilike",

       "~~*",

       "!~~*",

     ],

     +useWritePdo: false,

   }

 

 

DB::table('posts')->where('id','=',1)->get();

DB::table('posts')->where('id',1)->get();

DB::table('posts')->whereId('1')->get();

 

id가 1인 테이블 정보를 가져오는 똑같은 표현식입니다.

>>> DB::table('posts')->where('id','=',1)->get();

=> Illuminate\Support\Collection {#2932

     all: [

       {#2930

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

     ],

   }

>>> DB::table('posts')->where('id',1)->get();

=> Illuminate\Support\Collection {#2919

     all: [

       {#2899

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

     ],

   }


>>> DB::table('posts')->whereId('1')->get();

=> Illuminate\Support\Collection {#2924

     all: [

       {#2932

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

     ],

   }

 

 

DB::table('posts')->where(function($query){ $query->whereId(1); })->get();

콜백 함수로 where 절에 대한 조건문을 입력할 수 있어요.

 

>>> DB::table('posts')->where(function($query){ $query->whereId(1); })->get();

=> Illuminate\Support\Collection {#2937

     all: [

       {#2936

         +"id": 1,

         +"title": "hello chiro",

         +"contents": "고마워 tinker 야",

         +"regDate": "2020-02-12 16:12:02",

       },

     ],

   }

>>> 

 

+ Recent posts