PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

mysql_data_seek> <mysql_connect
Last updated: Sun, 25 Nov 2007

view this page in

mysql_create_db

(PHP 4, PHP 5, PECL mysql:1.0)

mysql_create_db — MySQL 데이터베이스를 생성

설명

bool mysql_create_db ( string $database_name [, resource $link_identifier ] )

mysql_create_db()는 link 지시자와 연결된 서버에 새로운 데이터베이스를 생성하도록 한다.

매개변수

database_name

생성될 데이터베이스 이름.

link_identifier

MySQL 연결. 지정하지 않으면 mysql_connect()로 연 마지막 연결을 사용합니다. 연결이 없으면, 매개변수 없이 mysql_connect()를 호출하여 연결을 만듭니다. 연결이 성립되지 않으면 E_WARNING 경고를 생성합니다.

반환값

성공할 경우 TRUE를, 실패할 경우 FALSE를 반환합니다.

예제

Example#1 mysql_create_db() 예제

mysql_create_db()의 사용은 권장되지 않는다. 대신, mysql_query()CREATE DATABASE 구문으로 질의하면 된다.

<?php
$link 
mysql_connect('localhost''mysql_user''mysql_password');
if (!
$link) {
    die(
'Could not connect: ' mysql_error());
}

$sql 'CREATE DATABASE my_db';
if (
mysql_query($sql$link)) {
    echo 
"Database my_db created successfully\n";
} else {
    echo 
'Error creating database: ' mysql_error() . "\n";
}
?>

위 예제의 출력 예:

Database my_db created successfully

주의

Note: 하위 호환을 위하여, 다음의 권장하지 않는 alias를 사용할 수 있습니다: mysql_createdb()

Note: 본 함수는 MySQL 4.x 클라이언트 라이브러리로 구축된 MySQL 확장이라면 사용이 불가능할 것이다.



add a note add a note User Contributed Notes
mysql_create_db
zubrag
29-Aug-2006 03:03
mysql_create_db function will not work on cPanel hosting. If you need to create database from your PHP script on cPanel hosted server then you'll need to use cPanel interface. Database creation code would look like (calling cPanel's adddb function): http://USER:PASS@HOST:2082/frontend/SKIN/sql/adddb.html?db=DB

You can download ready-made sample php script from http://www.zubrag.com/scripts/cpanel-database-creator.php
omer
20-Jun-2005 05:42
for MySQL4.1 lib users;

as noted the function is a no-go for MySQL4.1 libs.  While i do not know the logic behind this i was relieved to see that

mysql_connect ("localhost","$user","$password")
$soru = 'CREATE DATABASE '.$dbname;
mysql_query($soru);

worked just fine...

mysql_data_seek> <mysql_connect
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | stats | sitemap | contact | advertising | mirror sites