473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

I can't create New Database using PHP command on server. My coding is here...

<?
//phpmyadmin version on server 4.1.21

$DBSERVER = "localhost";
//$DATABASENAME = "test";
$USERNAME = "username";
$PASSWORD = "password";
$db=mysql_connect($DBSERVER, $USERNAME, $PASSWORD);

$dbname = 'testdb1';
mysql_query("CREATE DATABASE $dbname") or die("Couldn't Create Database: $dbname");

echo mysql_error();
?>

// THIS GIVES ME ERROR "Couldn't create Database : testdb1"
// i can create databse using this username and password through control panel of server.. why can't through PHP
May 4 '07 #1
4 2053
teesha
4
hi!
i think you need to select an existing database like this
$db=mysql_connect($server,$user,$passwd)or die("mysql_error());
mysql_select_db($mydatabase,$db)or die("mysql_error());

and then you can create a new database

mysql_query("CREATE DATABASE $my_new_database")
or die("Couldn't Create Database: $my_new_database");


i try it and run smoothly.
May 4 '07 #2
Thanks teesha,

very thanks for your reply, but u don't understand my question...

you said that first I select db using mysql_select_db... ok
then I create new db using mysql_query("CREATE ...");... ok

Now please tell me how can a database create with in existing database..

I just want to create a fresh new database when my user registered firstime.
For that i have to direct create a fresh database with random name and after that have to create predefined tables in that...


So, if you have any solution of that then please tell me.
May 4 '07 #3
devsusen
136 100+
Hi,

I don't think there is no such MySql function in php using that u can create a database. U can only drop a database.

IMO if u like to create a database in MySql only using php, then u need to execute direct mysql command using passthru() or exec() function.

susen
May 5 '07 #4
pbmods
5,821 Expert 4TB
I just want to create a fresh new database when my user registered firstime.
For that i have to direct create a fresh database with random name and after that have to create predefined tables in that...
Sounds like you might want to rethink your database design. One of the points of using MySQL is that you *don't* have to create a whole new database for each User. If you wanted to do that, you could just save data in text files in numbered folders on your server (not recommended).

Is it necessary for every User to have his own database (which would get VERY expensive on a shared server, btw), or could the problem be solved by adding a `userid` field to key tables to associate that data with a particular User?
May 5 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: R. Clausen | last post by:
I am wanting to create a database in UDB (WIN) v8 FP4 using a backup from UDB (WIN) v7.2 FP4. When the restore is complete, I get a DB2 Message 'The command completed successfully.', however, when...
7
by: Mullin Yu | last post by:
if i put the same code at the windows application or console, i can logon to the computer. but, if i put the same code at the windows service and start it, i still can't logon to the machine. ...
5
by: Gene | last post by:
What can I do if I want to get the result using the sql command? for example, the select command is "select Name from Employee where StaffID=10" How to get the "Name"??? dim Name as string and...
6
by: Greg P | last post by:
I am using VS2005 and have been learning a ton about databinding. I know that when you drag a view from the datasource window (creating a dataGridView) that an update method is not added to the...
8
by: lawrence k | last post by:
I've installed Apache 1.3.36 on my Redhat EL 3 machine. Now I'm trying to install PHP 5.1.4. I can not get the ./configure command to work. I keep getting this error: configure: error: Invalid...
2
by: Netkiller | last post by:
#!/usr/bin/python # -*- coding: utf-8 -*- """ Project: Network News Transport Protocol Server Program Description: 基于数据库的新闻组,实现BBS前端使用NNTP协议来访问贴子...
10
by: Miro | last post by:
I wanted certain text boxes ( only certain ones ) to always be Trim'd so that spaces are not in the begining, nor the end of the text entered. I created my own "Handle ?" - i hope thats the...
10
by: Benton | last post by:
Hi there, I have a UserControl with a couple of textboxes and a couple of buttons ("Save" and "Cancel"). The Click event for this buttons is in the UserControl's codebehind of course, so here's...
2
by: kirthi.amudha | last post by:
Hi, I have app dev client installed on my machine. Can we create the sample database using db2sampl. I was able to create database using the 'Create Database' command. But I am not able...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.