'MySQL'에 해당되는 글 3건

  1. 2009/08/18 PHP - mysql_fetch_array 와 mysql_fetch_row 의 차이점
  2. 2009/04/18 PHP mysql function 들
  3. 2009/04/10 MYSQL ALTER 문
두 함수간의 차이점은 어떠한 형태로 결과값을 반환하느냐이다. 예를들어, 다음과 같은 쿼리문을 실행하였다고 보자.

 

$query = "select * from table where id='lsk' ";

$result = mysql_query($query);

$values = mysql_fetch_row($result);
print_r($values);

//다음과 같은 결과값을 생성한다.

/*

Array(
[0]=>1,
[1]=>이슬기,
[2]=>lsk2017,
[3]=>243432

)

*/
즉, mysql_fetch_row 는 인덱스로 접근할수 있는 배열형태로 값을 반환한다. 반면에 mysql_fetch_array 는 연관배열값을 반환하는데, 다음과 같이 참조할수 있다.

추가내용 - mysql_fetch_assoc 는 연관배열값으로만 참조할수 있다.

foreach($values as $h=>$val){
echo $h."//".$val."<br/>";

}


Posted by 웹눈
TAG MySQL, PHP

PHP MySQL Functions

PHP: indicates the earliest version of PHP that supports the function.

FunctionDescriptionPHP
mysql_affected_rows() Returns the number of affected rows in the previous MySQL operation 3
mysql_change_user() Deprecated. Changes the user of the current MySQL connection 3
mysql_client_encoding() Returns the name of the character set for the current connection 4
mysql_close() Closes a non-persistent MySQL connection 3
mysql_connect() Opens a non-persistent MySQL connection 3
mysql_create_db() Deprecated. Creates a new MySQL database. Use mysql_query() instead 3
mysql_data_seek() Moves the record pointer 3
mysql_db_name() Returns a database name from a call to mysql_list_dbs() 3
mysql_db_query() Deprecated. Sends a MySQL query. Use mysql_select_db() and mysql_query() instead 3
mysql_drop_db() Deprecated. Deletes a MySQL database. Use mysql_query() instead 3
mysql_errno() Returns the error number of the last MySQL operation 3
mysql_error() Returns the error description of the last MySQL operation 3
mysql_escape_string() Deprecated. Escapes a string for use in a mysql_query. Use mysql_real_escape_string() instead 4
mysql_fetch_array() Returns a row from a recordset as an associative array and/or a numeric array 3
mysql_fetch_assoc() Returns a row from a recordset as an associative array 4
mysql_fetch_field() Returns column info from a recordset as an object 3
mysql_fetch_lengths() Returns the length of the contents of each field in a result row 3
mysql_fetch_object() Returns a row from a recordset as an object 3
mysql_fetch_row() Returns a row from a recordset as a numeric array 3
mysql_field_flags() Returns the flags associated with a field in a recordset 3
mysql_field_len() Returns the maximum length of a field in a recordset 3
mysql_field_name() Returns the name of a field in a recordset 3
mysql_field_seek() Moves the result pointer to a specified field 3
mysql_field_table() Returns the name of the table the specified field is in 3
mysql_field_type() Returns the type of a field in a recordset 3
mysql_free_result() Free result memory 3
mysql_get_client_info() Returns MySQL client info 4
mysql_get_host_info() Returns MySQL host info 4
mysql_get_proto_info() Returns MySQL protocol info 4
mysql_get_server_info() Returns MySQL server info 4
mysql_info() Returns information about the last query 4
mysql_insert_id() Returns the AUTO_INCREMENT ID generated from the previous INSERT operation 3
mysql_list_dbs() Lists available databases on a MySQL server 3
mysql_list_fields() Deprecated. Lists MySQL table fields. Use mysql_query() instead 3
mysql_list_processes() Lists MySQL processes 4
mysql_list_tables() Deprecated. Lists tables in a MySQL database. Use mysql_query() instead 3
mysql_num_fields() Returns the number of fields in a recordset 3
mysql_num_rows() Returns the number of rows in a recordset 3
mysql_pconnect() Opens a persistent MySQL connection 3
mysql_ping() Pings a server connection or reconnects if there is no connection 4
mysql_query() Executes a query on a MySQL database 3
mysql_real_escape_string() Escapes a string for use in SQL statements 4
mysql_result() Returns the value of a field in a recordset 3
mysql_select_db() Sets the active MySQL database 3
mysql_stat() Returns the current system status of the MySQL server 4
mysql_tablename() Deprecated. Returns the table name of field. Use mysql_query() instead 3
mysql_thread_id() Returns the current thread ID 4
mysql_unbuffered_query() Executes a query on a MySQL database (without fetching / buffering the result) 4


PHP MySQL Constants

Since PHP 4.3 it has been possible to specify additional flags for the mysql_connect() and mysql_pconnect() functions:

PHP: indicates the earliest version of PHP that supports the constant.

ConstantDescriptionPHP
MYSQL_CLIENT_COMPRESS Use compression protocol 4.3
MYSQL_CLIENT_IGNORE_SPACE Allow space after function names 4.3
MYSQL_CLIENT_INTERACTIVE Allow interactive timeout seconds of inactivity before closing the connection 4.3
MYSQL_CLIENT_SSL Use SSL encryption (only available with version 4+ of the MySQL client library) 4.3

The mysql_fetch_array() function uses a constant for the different types of result arrays. The following constants are defined:

ConstantDescriptionPHP
MYSQL_ASSOC Columns are returned into the array with the fieldname as the array index  
MYSQL_BOTH Columns are returned into the array having both a numerical index and the fieldname as the array index  
MYSQL_NUM Columns are returned into the array having a numerical index (index starts at 0)  

'프로그래밍 > PHP' 카테고리의 다른 글

$_SERVER 변수  (0) 2009/04/19
PHP mysql function 들  (0) 2009/04/18
PHP 파일업로드 구현시 보안문제 해결방안.  (0) 2009/04/17
exlode() 배열 관리 외부파일 배열 생성하기  (1) 2009/04/16
Posted by 웹눈
TAG MySQL
새로운 열 추가하기
mysql > ALTER TABLE 테이블명 ADD (추가할row명 varchar(20));

 속성 바꾸기

MODIFY

열 삭제하기

DROP

테이블 이름 바꾸기

RENAME

칼럼 이름 바꾸기

CHANGE

'프로그래밍 > PHP' 카테고리의 다른 글

PHP 이메일 보내기  (0) 2009/04/12
PHP mysql 로우 열 갯수 구하기  (0) 2009/04/11
MYSQL ALTER 문  (0) 2009/04/10
PHP 파일 업로드  (0) 2009/04/10
Posted by 웹눈
TAG MySQL