php mysql 지원 함수들

|

http://php.net 에서 다음의 함수들을 찾아보실 수 있고, 자세한 설명과 샘플을

확인하실 수 있습니다. :)

 

mysql_affected_rows -- 최근 MySQL 작업으로 처리된 행(row) 개수를 얻음
mysql_change_user --  현 접속에서 로그인된 사용자를 변경
mysql_client_encoding -- Returns the name of the character set
mysql_close -- MySQL 접속을 닫음
mysql_connect -- MySQL 서버에 접속
mysql_create_db -- MySQL 데이터베이스를 생성
mysql_data_seek -- 내부적인 결과 포인터를 이동
mysql_db_name -- 데이터 결과를 얻음
mysql_db_query -- MySQL 질의문을 전송
mysql_drop_db -- MySQL 데이터베이스를 삭제
mysql_errno -- 최근 MySQL 작업으로 발생한 에러 번호를 반환
mysql_error -- 최근 실행된 MySQL 작업으로 발생한 에러 메시지를 반환
mysql_escape_string --  Escapes a string for use in a mysql_query.
mysql_fetch_array --  결과를 필드이름 색인 또는 숫자 색인으로 된 배열로 반환
mysql_fetch_assoc --  결과를 필드이름 색인으로 된 배열로 반환
mysql_fetch_field --  결과로부터 열 정보를 얻어서 객체로 반환
mysql_fetch_lengths --  결과로부터 각 출력의 길이를 반환
mysql_fetch_object -- 행(row)의 결과를 객체로 얻음
mysql_fetch_row -- 결과를 숫자색인으로 된 배열로 반환
mysql_field_flags --  결과로부터 특정 필드(field)의 상태정보(flag)를 반환
mysql_field_len --  특정 필드의 길이를 반환
mysql_field_name --  결과로부터 특정 필드 이름을 반환
mysql_field_seek --  특정 필드의 오프셋(offset)으로 위치(pointer)를 이동
mysql_field_table --  특정 필드가 속한 테이블 이름을 얻음
mysql_field_type --  결과로부터 특정 필드의 데이터 형(type) 정보를 반환
mysql_free_result -- Free result memory
mysql_get_client_info -- Get MySQL client info
mysql_get_host_info -- Get MySQL host info
mysql_get_proto_info -- Get MySQL protocol info
mysql_get_server_info -- Get MySQL server info
mysql_info --  Get information about the most recent query
mysql_insert_id --  최근 INSERT 작업으로부터 생성된 identifier 값을 반환
mysql_list_dbs --  MySQL 서버에 있는 데이터베이스 이름을 반환
mysql_list_fields -- MySQL 결과의 필드 리스트로 반환
mysql_list_processes -- List MySQL processes
mysql_list_tables -- MySQL 데이터베이스에 있는 테이블 목록을 반환
mysql_num_fields -- 결과로부터 필드 개수를 반환
mysql_num_rows -- 결과로부터 열 개수를 반환
mysql_pconnect --  MySQL 서버와 영구적인 데이터베이스 접속
mysql_ping -- Ping a server connection or reconnect if there is no connection
mysql_query -- Send a MySQL query
mysql_real_escape_string --  Escapes special characters in a string for use in a SQL statement, taking into account the current charset of the connection.
mysql_result -- 결과 데이터를 반환
mysql_select_db -- MySQL 데이터베이스를 선택
mysql_stat -- Get current system status
mysql_tablename -- 필드의 테이블이름을 얻음
mysql_thread_id -- Return the current thread ID
mysql_unbuffered_query --  Send an SQL query to MySQL, without fetching and buffering the result rows


아래는 사용 샘플입니다.

 

<?php
/* 접속하고, 데이터베이스를 선택 */
$link mysql_connect("mysql_host""mysql_user""mysql_password"
)
   or die(
"접속할 수 없습니다 : " mysql_error
());
echo 
"접속 성공"
;
mysql_select_db("my_database") or die("데이터베이스를 선택할 수 없습니다."
);

/* SQL 쿼리 실행하기 */
$query "SELECT * FROM my_table"
;
$result mysql_query($query) or die("쿼리 실패 : " mysql_error
());

/* HTML로 결과 출력하기 */
echo "<table>n"
;
while (
$line mysql_fetch_array($resultMYSQL_ASSOC
)) {
   echo 
"t<tr>n"
;
   foreach (
$line as $col_value
) {
       echo 
"tt<td>$col_value</td>n"
;
   }
   echo 
"t</tr>n"
;
}
echo 
"</table>n"
;

/* 결과셋 해제하기 */
mysql_free_result($result
);

/* 접속 종료 */
mysql_close($link
);
?>


Trackback 0 And Comment 0

phpmyadmin 미리 작성된 sql 파일 import 하기

|


friend2.sql






sql 파일을 미리 만들고




phpmyadmin의 임포트 메뉴로 가서 파일을선택하고 아래의 go를 누르면 sql 파일 명령이 실행되서 테이블이 생성된다.

Trackback 0 And Comment 0

데이터베이스 테이블 설계(테이블 수정)

|
새로운 필드 추가 명령

alter table 테이블명 add 새로운 필드명 필드 타입 [first 또는 after 필드명];

예) 
앞서 만든 friend 테이블에 나이 필드를 (정수형)을 추가하려면 다음과 같이 입력한다.



만약 tel 필드 다음에 휴대폰 번호를 저장하는 hp char(20)인 필드를 추가하려면 다음과 같이 입력한다.

alter table friend add hp char(20) after tel;


필드 삭제 명령


alter table 테이블명 drop 삭제할 필드명1, 삭제할 필드명2;



friend 테이블의 email 필드와 age 필드를 삭제하려면 다음과 같이 입력한다.


alter table friend drop email;

alter table friend drop age;




필드 수정 명령


alter table 테이블명 change 이전 필드명 새로운 필드명 필드 타입;


예)

tel char(20)을 phone int로 변경하고 싶으면


alter table friend chage tel phone int;



필드 타입 수정 명령

alter table 테이블명 modify 필드명 새로운 타입;


name 필드의 타입을 int로 변경하려면


alter table friend modify name int;



데이터 베이스 테이블명 수정 명령

alter table 이전 테이블명 rename 새로운 테이블명;


테이블명을 friend -> student 로 변경하고 싶으면


alter table friend rename student;



데이터베이스 테이블 삭제 명령

drop table 테이블명;


friend 테이블을 삭제하고 싶으면


drop table friend;





Trackback 0 And Comment 0