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
mysql_create_db
(PHP 4, PHP 5, PECL mysql:1.0)
mysql_create_db — Create a MySQL database
說明
mysql_create_db() attempts to create a new database on the server associated with the specified link identifier.
參數
- database_name
-
The name of the database being created.
- link_identifier
-
MySQL 的連接識別符。如果沒有指定,預設使用最後被 mysql_connect() 打開的連接。如果沒有找到該連接,函式會嘗試呼叫 mysql_connect() 建立連接並使用它。如果發生意外,沒有找到連接或無法建立連接,系統發出 E_WARNING 級別的警告信息。
Return值
如果成功則回傳 TRUE,失敗則回傳 FALSE。
範例
Example#1 mysql_create_db() alternative example
The function mysql_create_db() is deprecated. It is preferable to use mysql_query() to issue a sql CREATE DATABASE statement instead.
<?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: 為了保證向下相容性,可以使用下面的別名,但不贊成使用它: mysql_createdb()
Note: This function will not be available if the MySQL extension was built against a MySQL 4.x client library.
mysql_create_db
29-Aug-2006 10:03
21-Jun-2005 12: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...
