Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-15-2009, 12:01 AM
Junior Member
Latest Blog:
None

 
Join Date: 11-14-09
Posts: 3
iTrader: 0 / 0%
Etherwood is liked by many
PHP & MySQL

Is it possible to create a new database, create new users, and grant permissions using a php INSERT query or does it have to be done at root?
Share |
Reply With Quote
  #2 (permalink)  
Old 11-15-2009, 02:03 AM
DH - Tristan Perry's Avatar
Contributing Member
Latest Blog:
None

 
Join Date: 11-07-09
Location: Cardiff, UK
Posts: 151
iTrader: 0 / 0%
DH - Tristan Perry is a jewel in the roughDH - Tristan Perry is a jewel in the roughDH - Tristan Perry is a jewel in the roughDH - Tristan Perry is a jewel in the roughDH - Tristan Perry is a jewel in the roughDH - Tristan Perry is a jewel in the rough
It's not possible to do this via an INSERT SQL query, no. INSERT is to a row of data into a database table.

I think you'd need to login to your control panel to create a new user, in a standard PHP/MySQL set-up.
__________________
Devoted Hosting
High Quality Shared And Reseller Hosting
cPanel, 24/7 support, 99.9% uptime guaranteed
Share |
Reply With Quote
  #3 (permalink)  
Old 11-15-2009, 02:58 AM
megamoose's Avatar
v7n Mentor
Latest Blog:
None

 
Join Date: 06-04-06
Location: London
Posts: 521
iTrader: 2 / 100%
megamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to allmegamoose is a name known to all
Send a message via ICQ to megamoose Send a message via MSN to megamoose Send a message via Yahoo to megamoose Send a message via Skype™ to megamoose
To create a table in MySQL:

Code:
$result = mysql_query("CREATE DATABASE mydatabase");
Obviously you have to connect to the MySQL server first, but I'm sure you can do that already. That line above will create a new database. Note that if you are not logging in as the root user (which you should always create a separate user for separate sites/scripts anyway), that you will need to make sure that user has access to create databases.
__________________
Microsoft Office doesn't correct Chuck Norris. Chuck Norris corrects Microsoft Office.
Share |
Reply With Quote
  #4 (permalink)  
Old 11-15-2009, 06:04 AM
ScriptMan's Avatar
Super Moderator
Latest Blog:
None

 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 2,756
iTrader: 3 / 100%
ScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest orderScriptMan is a web professional of the highest order
Quote:
Originally Posted by Etherwood View Post
Is it possible to create a new database, create new users, and grant permissions using a php INSERT query or does it have to be done at root?
Sounds like you are on a VPS or dedi. If you don't already have phpmyadmin

http://www.phpmyadmin.net/home_page/index.php

why don't you download and install it. For sure to make your life far easier in the long run.

Might be available as a YUM auto install. I did not look to see.
__________________
These forums are as good as the posts that you contribute to them.~~
ScriptMan
Webmaster Help Articles
Share |
Reply With Quote
  #5 (permalink)  
Old 11-15-2009, 07:19 AM
Hades's Avatar
Senior Web Developer
Latest Blog:
None

 
Join Date: 01-23-07
Location: Argentina
Posts: 2,231
iTrader: 0 / 0%
Hades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest orderHades is a web professional of the highest order
PHP has nothing to do with the type of queries that you run on the DB.

With PHP (or any other language, platform, etc) you can do anything that the database user is allowed to do. So if you are connected to the database with a user that has administrative privileges, you can run any ALTER, CREATE, DROP statements. If you are connected with an account that only has data privileges you can run only INSERTS, UPDATES, DELETES, TRUNCATE, etc.

So the answer to your question is, yes, you can run administrative queries from a PHP script, but you need to know 2 things:
1-if the user that is connecting to the DB has administrative permissions.
2-how to write those administrative queries (they are not INSERTS).

For reference on how to write the DDL SQL commands, suggested reading:
http://dev.mysql.com/doc/refman/5.1/...efinition.html

For reference on how to manage database users:
http://dev.mysql.com/doc/refman/5.1/...anagement.html
__________________
Cristian Espinoza ~ Sr. Web Developer
Currently available for Freelance Web Development

(+54 9) 1155 601 661
Skype: espinoza.cristian

Last edited by Hades; 11-15-2009 at 07:30 AM.
Share |
Reply With Quote
  #6 (permalink)  
Old 11-15-2009, 07:43 AM
Contributing Member
Latest Blog:
None

 
Join Date: 09-06-09
Posts: 549
iTrader: 3 / 100%
websiteguy is liked by somebodywebsiteguy is liked by somebodywebsiteguy is liked by somebodywebsiteguy is liked by somebody
if you have cpanel than you can create a new database with mysql wizard.
if you are using ssh than you have to login with mysql user make sure you have db creation rights.
command: create database dbname;
also many panels provide your phpmyadmin you can create db and assign rights to user with it
__________________
cpanel hosting : cpanel host
quality+affordability $2.5/m only
Share |
Reply With Quote
Go Back   Webmaster Forum > Web Development > Coding Forum

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL help please D: splap Coding Forum 3 08-24-2009 05:23 AM
MySql vs. MS SQL Muddy Web Hosting Forum 13 02-28-2009 08:28 AM
MySQL? rob7676 Coding Forum 5 07-11-2008 04:53 PM
Need help with PhP MySQL JustRetarded Coding Forum 4 08-15-2007 11:12 PM
Fun with mysql nasty.web Tech Talk 5 10-20-2006 10:38 AM


Sponsor Links
Get exposure! Contextual Links V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 11:52 AM.
© Copyright 2010 V7 Inc
Powered by vBulletin
Copyright © 2000-2010 Jelsoft Enterprises Limited.


Search Engine Optimization by vBSEO 3.3.0 ©2009, Crawlability, Inc.