MySQL 필드의 이름을 불러오는 함수 mysql_field_name  DB 관련 함수

 

필드의 이름을 불러오는 함수는

 

mysql_field_name()

 

이다.

 

mysql_field_name (쿼리변수,필드순서);

 

 

사용법 :

 

<?
mysql_connect("localhost", "root", "apmsetup");
mysql_select_db("hello");

$result = mysql_query("SELECT * FROM user_tbl WHERE userid = 'david'");


$res = mysql_query('select * from user_tbl');

echo mysql_field_name($res, 0)
 ?>

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

MySQL 필드의 바이트 값을 구하는 함수 mysql_field_len()  DB 관련 함수


필드의 바이트 값을 구하는 함수는 mysql_field_len()이다.

 

사용법은

 

 <?
mysql_connect("localhost", "root", "apmsetup");
mysql_select_db("hello");

$result = mysql_query("SELECT * FROM user_tbl WHERE userid = 'david'");


$length = mysql_field_len($result, 5);
echo $length;


 ?>

 

결과 

 

11

---------------------------------------------

 

 

 

 

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

MySQL 행과 일치하는 값의 레코드 불러오기 mysql_fetch_row()  DB 관련 함수


<?
mysql_connect("localhost", "root", "apmsetup");
mysql_select_db("hello");

$result = mysql_query("select *from user_tbl where userid = 'david'");
if(!$result){
 echo mysql_error();
 exit;
}
$row = mysql_fetch_row($result);

$sql = mysql_query("select *from user_tbl");
$num_fields = mysql_num_fields($sql);

 

for($a = 0; $a < $num_fields;$a++){
 echo "$a :  $row[$a] <br />";
}
 ?>

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

MySQL 테이블의 필드의 갯수를 구하는 함수 mysql_num_fields()  DB 관련 함수

 

MySQL 에서 테이블의 필드를 수를 구하는 함수는 mysql_num_fiedls() 이다.

 

그럼 소스를 통해서 살펴보자.

 

<?php
$conn = mysql_connect("localhost","root","apmsetup") or die ("My SQL connection Error");

mysql_select_db('hello');


$result = mysql_query('select *from user_tbl') or die("no table");

$a = mysql_num_fields($result);  //
 
echo "필드의 갯수 : $a ";


?>

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

MySQL 에러번호 반환 함수 mysql_errno()  DB 관련 함수

 

MySQL 함수에서 에러 번호를 반환 하는 함수가 있다. 

 

함수명 : mysql_errno()

 

사용법

 

 <?
$host = "localhost";
$user = "root";
$password = "apmsetup";

$link = mysql_connect($host,$user,$password) or die ("mysql connection error");
if (!mysql_select_db("nonexistentdb", $link)) {
    echo mysql_errno($link) . ": " . mysql_error($link). "\n";
}

mysql_select_db("kossu", $link);
if (!mysql_query("SELECT * FROM nonexistenttable", $link)) {
    echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
}
?>

 

 

위 소스 출력시 아래와 같은 결과가 출력 된다.

 

1049: Unknown database 'nonexistentdb' 1046: No database selected

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

- MySQL 데이터 베이스를 삭제 -

 

MySQL 데이터 베이스 삭제 하기 drop database DB명  DB 관련 함수

mysql_drop_db 라고 하는 함수가 있지만 권장하지 않으면

drop database DBNAME를 사용하는것을 권장한다.

 

<?
$host = "localhost";
$user = "root";
$password = "apmsetup";

$connect = mysql_connect($host,$user,$password) or die ("mysql connection error");


$sql = "drop database my_db";
mysql_query($sql,$connect);

?>

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

자신의 MySQL안에 있는 데이터 베이스 목록을 불러오기 위해서서는

 mysql_list_dbs() 과 mysql_db_name()

 

라는 함수를 사용 한다.

 

사용법 :

 

<?
$host = "localhost";
$user = "root";
$password = "apmsetup";

$connect = mysql_connect($host,$user,$password) or die ("mysql connection error");
$db_list = mysql_list_dbs($connect);

$cnt = mysql_num_rows($db_list);

for($a=0;$a<$cnt;$a++){
 echo mysql_db_name($db_list,$a);
 echo "<br />";
 }
 

?>

 

 

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,

mysql_create_db

라는 함수가 있지만

잘 사용하지 않으며

아래와 같이 쿼리문을 사용하는 추세이다.

 

<?
$host = "localhost";
$user = "root";
$password = "apmsetup";

$connect = mysql_connect($host,$user,$password) or die ("mysql connection error");
mysql_select_db("hello",$connect);

$sql = "create database my_db";

$res = mysql_query($sql,$connect);

if($res){
echo "good";
}
else{
echo "not good";
}

?>

블로그 이미지

itworldkorea

IT korea가 세상(world)을 변화시킨다.

,