Unstoppable Domains โ€” Expired Auctions

Making a new database in PHP

SpaceshipSpaceship
Watch
Impact
19
Hey
is there a way to make a new Database in PHP? in a php script...i cant figure it outt...Thanks
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I'm not sure, but I believe the command to use is create database
PHP:
<?php
// Possibly something like this:
mysql_connect('blah', 'blah', 'blah);
mysql_query('create database blah');
mysql_close();
?>
 
0
•••
uh... i don't think that will work. when you make a database you need to specify the type(s) of data you are feeding into it... if you can anticipate this then just make a blank database.
 
0
•••
the types of data are specified in the tables;

you can create a database with
PHP:
$query  = "CREATE DATABASE test_database";
$result = mysql_query($query);
or
PHP:
mysql_create_db('test_database');

After that you can select that database and create tables in it
PHP:
mysql_select_db('test_database') or die('Cannot select database');

$query = 'CREATE TABLE users( '.
         'id INT NOT NULL AUTO_INCREMENT, '.
         'name VARCHAR(20) NOT NULL, '.
         'email VARCHAR(50) NOT NULL, '.
         'message TEXT NOT NULL, '.
         'PRIMARY KEY(id))';

$result = mysql_query($query);
 
0
•••
as Slewey states you can use the mysql_create_db function but the user you connect with must have permissions to create a database.
 
0
•••
well i can make databases through cpanel..but i cant seem to do it using PHP...in the user thing..do i put my username and password for Cpanel/
 
0
•••
unknowngiver said:
well i can make databases through cpanel..but i cant seem to do it using PHP...in the user thing..do i put my username and password for Cpanel/

No, in cPanel you must make a user with the ability to make a database. Then you use those user's details when conencting via php.
 
0
•••
Access denied for user 'funny_dbmaker'@'%' to database 'funny_blah'

in cpanel there is no way of setting a user to make databases i think? u can only assign a user to specific databases 2 perform stuff on them..
 
0
•••
unknowngiver said:
well i can make databases through cpanel..but i cant seem to do it using PHP...in the user thing..do i put my username and password for Cpanel/

cPanel uses the adminitrator account if I remember correctly to create a database. Just had a look at the mysql user creation page as well and it seems that cPanel does not give the ability to let an account create a database 9only tables hence the create privaleges)
 
0
•••
So theres no way of making databases in PHP?

btw i remember seeing a site [some1 posted it on namepros] once where u typed in your cpanel information 2 make newdatabses throuigh that site..so it should be possible i guess?
 
0
•••
unknowngiver said:
So theres no way of making databases in PHP?

Only if the user you are connecting with has the privileges to create a database and cpanel does not allow you to give that right.

unknowngiver said:
btw i remember seeing a site [some1 posted it on namepros] once where u typed in your cpanel information 2 make newdatabses throuigh that site..so it should be possible i guess?

They most likely used cURL which would simulate someone doing it manually.

EDIT
----

Just had a look and the following seems to be the sort of script you mean http://www.zubrag.com/scripts/cpanel-database-creator.php

cPanel does not allow you to create databases directly from MySQL/PhpMyAdmin on cPanel webhosting. You would have to login to cPanel and use its interface to create database each time you need a new one.
cPanel Database Creator will make this process much easier. In order to create a database on your hosting server you just need to run this script from browser, shell, or cron job, passing database name as parameter.

If you look on the site you will see the system requirements are that cURL is installed. This will basically log into cPanel and basically act as if you were creating it yourself.
 
Last edited:
0
•••
hm pretty gud:) buh how would u add a user now?
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Spaceship
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back