473,701 Members | 2,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Create Mysql database?


How do I make PHP create a database for mysql please?
I can see how to make tables and I have read all the documents
I can find but I don't understand how to make the database itself.

All the tutorials I can find seem to bypass the issue by ignoring it?

Am I missunderstandi ng something?

Thanks
May 11 '07 #1
15 2680
On Fri, 11 May 2007 16:42:23 +0000, harvey wrote:
How do I make PHP create a database for mysql please?
query = "create database fred;";
May 11 '07 #2
In article <pa************ *************** *@you.now>, an*****@you.now
says...
On Fri, 11 May 2007 16:42:23 +0000, harvey wrote:
How do I make PHP create a database for mysql please?

query = "create database fred;";
Oh god is it really that simple - this must be my day
for asking dumb questions.

Thanks for not lauging at me... at least not in public !
May 11 '07 #3
On 11 May, 17:52, harvey <harvey....@blu eyonzders.comwr ote:
In article <pan.2007.05.11 .16.45.46.763.. .@you.now>, anno...@you.now
says...
On Fri, 11 May 2007 16:42:23 +0000, harvey wrote:
How do I make PHP create a database for mysql please?
query = "create database fred;";

Oh god is it really that simple - this must be my day
for asking dumb questions.

Thanks for not lauging at me... at least not in public !
remember though that it's considered good practise not to have php
use root, give php too many permissions and it will only be time
before your hard work comes back to haunt you, instead get use
to creating the db using the mysql command line (or some helpful gui)
and then immediately create a new user which has rights over this
database, and plug that into the php scripts that use that db,
limiting potential for disaster.

May 11 '07 #4
In article <11************ **********@y80g 2000hsf.googleg roups.com>,
ma********@gmai l.com says...
remember though that it's considered good practise not to have php
use root, give php too many permissions and it will only be time
before your hard work comes back to haunt you, instead get use
to creating the db using the mysql command line (or some helpful gui)
and then immediately create a new user which has rights over this
database, and plug that into the php scripts that use that db,
limiting potential for disaster.

hmmm... I can see that this is likely to get very complicated very
quickly.

My difficlty is I am at the learning stage with PHP and mySQL but I'm
doing this to try and automate the procedures for someone who knows even
less than I do. I need it to create the database and tables and
then update the tables for him from forms in his browser -

I can do most of it but the PHP/Mysql is new to me as I said.

I've bought the Samms PHP,MYsql and Apache - All in One book and am
working through it to get this done but it tends to gloss over
or even ignore the really important stuff such as that you just
mentioned. I'm reasonably Linux oriented so most of it makes sense but
where issues don't arise at all I can miss them. (I'm not at all
impressed with most of the books I've seen I must admit but this one did
seem the best)

Do you have any advice for me on using PHP to create the database appart
from not doing it? (I suspect he doesnt have root access on his web site
either so I'm guessing he needs to use his own ISP provided access - he
does have the mySQL admin package but not the skills to use it -)

Is there anything I can do to limit the problems of creating the database
in PHP? I really don't want to try and get him to do anything manually.
Thanks again.
May 11 '07 #5
On May 11, 10:39 am, harvey <harvey....@blu eyonzders.comwr ote:

Is there anything I can do to limit the problems of creating the database
in PHP? I really don't want to try and get him to do anything manually.

Thanks again.

Many programs have a "database setup" script that asks for the MySQL
root password and then creates the tables and users for the main
program to use later (the db 'user' it creates has limited
functionality so it cannot mess with other databases or create/delete
tables.) It never records the root PW, once the MySQL users and
tables are done it utilizes only the limited accounts it created.
(probably only requiring root PW later for major upgrades)

May 11 '07 #6
Tom

"harvey" <ha********@blu eyonzders.comwr ote in message
news:MP******** *************** *@news-text.blueyonder .co.uk...
In article <pa************ *************** *@you.now>, an*****@you.now
says...
On Fri, 11 May 2007 16:42:23 +0000, harvey wrote:
How do I make PHP create a database for mysql please?
query = "create database fred;";


Oh god is it really that simple - this must be my day
for asking dumb questions.

Thanks for not lauging at me... at least not in public !
If MySQL was already installed, running, and configured in your PHP setup,
then you should be fine. If you see permission errors though, you might need
to check up on the permission settings in your MySQL setup.

If you do need to, I'd check the MySQL documentation
(http://dev.mysql.com/doc/) on "user account management" to make sure your
username and/or network location (IP address, localhost, etc.) are
configured for access.

Tom
--
Newsguy.com
90+ Days Retention
Higher levels of article completion
Broader newsgroups coverage
May 11 '07 #7
On Fri, 11 May 2007 10:16:55 -0700, shimmyshack wrote:
On 11 May, 17:52, harvey <harvey....@blu eyonzders.comwr ote:
>In article <pan.2007.05.11 .16.45.46.763.. .@you.now>, anno...@you.now
says...
On Fri, 11 May 2007 16:42:23 +0000, harvey wrote:
How do I make PHP create a database for mysql please?
query = "create database fred;";

Oh god is it really that simple - this must be my day
for asking dumb questions.
Just think of PHP as your front end to your SQL server... anything you can
do in standard ANSI SQL you can do with PHP.
>Thanks for not lauging at me... at least not in public !

remember though that it's considered good practise not to have php
use root, give php too many permissions and it will only be time
before your hard work comes back to haunt you, instead get use
to creating the db using the mysql command line (or some helpful gui)
and then immediately create a new user which has rights over this
database, and plug that into the php scripts that use that db,
limiting potential for disaster.
PHP/Apache/mysql/etc should never run as root and never have to. There
should be no correlation between the accounts used by your public apps and
the system accounts on the box.

That's a fine solution unless you're creating databases dynamically...
which is the only reason I can think of to create a DB with a web
application in the first place.

There is a simple solution however. Control the rights of the web app
using your mysql install. I have one user that has read-only access to the
databases for use when doing look-ups, one user that I grant write access
to the databases for operations that need to write to the database and one
with access to create databases.

I set the default user for my connection to the read-only account and have
to purposefully change the account being used if I want to do anything
other than just read.

You can't inject SQL if the account you're using doesn't have rights to
write to the database.

May 11 '07 #8

"harvey" <ha********@blu eyonzders.comwr ote in message
news:MP******** *************** *@news-text.blueyonder .co.uk...
In article <11************ **********@y80g 2000hsf.googleg roups.com>,
ma********@gmai l.com says...
>remember though that it's considered good practise not to have php
use root, give php too many permissions and it will only be time
before your hard work comes back to haunt you, instead get use
to creating the db using the mysql command line (or some helpful gui)
and then immediately create a new user which has rights over this
database, and plug that into the php scripts that use that db,
limiting potential for disaster.


hmmm... I can see that this is likely to get very complicated very
quickly.

My difficlty is I am at the learning stage with PHP and mySQL but I'm
doing this to try and automate the procedures for someone who knows even
less than I do. I need it to create the database and tables and
then update the tables for him from forms in his browser -

I can do most of it but the PHP/Mysql is new to me as I said.

I've bought the Samms PHP,MYsql and Apache - All in One book and am
working through it to get this done but it tends to gloss over
or even ignore the really important stuff such as that you just
mentioned. I'm reasonably Linux oriented so most of it makes sense but
where issues don't arise at all I can miss them. (I'm not at all
impressed with most of the books I've seen I must admit but this one did
seem the best)

Do you have any advice for me on using PHP to create the database appart
from not doing it? (I suspect he doesnt have root access on his web site
either so I'm guessing he needs to use his own ISP provided access - he
does have the mySQL admin package but not the skills to use it -)

Is there anything I can do to limit the problems of creating the database
in PHP? I really don't want to try and get him to do anything manually.
Its actually quite easy. I too haven't done much in it but I'm pretty much
able to do all basic database stuff I need to.

Essentially you first log into the database using a function, create a sql
query string(which is probably going to be the hardest part but it too is
quite simple once you get over the mental block), and then query the
database with another function.

for example, heres a query for my database to check some stuff

$query="DELETE FROM ips WHERE ip='".mysql_rea l_escape_string ($RMADDR,
$ldblink)."';";
$result = queryldb($query , $ldblink);
function logonldb($datab ase)
{
$user="login";
$password="pass word";

$link = mysql_connect(' localhost', $user, $password);
if (!$link) { dberror("Connec tion Error!"); }

$db_selected = mysql_select_db ($database, $link);
if (!$db_selected) { dberror("Databa se Error!"); }

return $link;
}
and I use loginldb to log into the database and return the link that is used
in the calls. You also have to log out with somethign like
function logoffldb($link )
{
mysql_close($li nk);
}

the query function is defined as

function queryldb($query , $link)
{

$result = mysql_query($qu ery, $link);
return $result;
}

also, if you are to get a result then you want to convert the query call
into an array using something like the following

if ($result != false) { $row = mysql_fetch_ass oc($result); if ($row ==
false) { unset($row);}} else unset($row);
My wrappers are kinda unnecessary but hopefully you can see how basic it is.
Its just a few function calls and a little bit of setup(query string and
result conversion).
Its much easier than I ever expected and was a relief.

Jon
May 11 '07 #9

"Jon Slaughter" <Jo***********@ Hotmail.comwrot e in message
news:Yx******** ********@newssv r21.news.prodig y.net...
>
"harvey" <ha********@blu eyonzders.comwr ote in message
news:MP******** *************** *@news-text.blueyonder .co.uk...
>In article <11************ **********@y80g 2000hsf.googleg roups.com>,
ma********@gmai l.com says...
>>remember though that it's considered good practise not to have php
use root, give php too many permissions and it will only be time
before your hard work comes back to haunt you, instead get use
to creating the db using the mysql command line (or some helpful gui)
and then immediately create a new user which has rights over this
database, and plug that into the php scripts that use that db,
limiting potential for disaster.


hmmm... I can see that this is likely to get very complicated very
quickly.

My difficlty is I am at the learning stage with PHP and mySQL but I'm
doing this to try and automate the procedures for someone who knows even
less than I do. I need it to create the database and tables and
then update the tables for him from forms in his browser -

I can do most of it but the PHP/Mysql is new to me as I said.

I've bought the Samms PHP,MYsql and Apache - All in One book and am
working through it to get this done but it tends to gloss over
or even ignore the really important stuff such as that you just
mentioned. I'm reasonably Linux oriented so most of it makes sense but
where issues don't arise at all I can miss them. (I'm not at all
impressed with most of the books I've seen I must admit but this one did
seem the best)

Do you have any advice for me on using PHP to create the database appart
from not doing it? (I suspect he doesnt have root access on his web site
either so I'm guessing he needs to use his own ISP provided access - he
does have the mySQL admin package but not the skills to use it -)

Is there anything I can do to limit the problems of creating the database
in PHP? I really don't want to try and get him to do anything manually.

Its actually quite easy. I too haven't done much in it but I'm pretty much
able to do all basic database stuff I need to.

Essentially you first log into the database using a function, create a sql
query string(which is probably going to be the hardest part but it too is
quite simple once you get over the mental block), and then query the
database with another function.

for example, heres a query for my database to check some stuff

$query="DELETE FROM ips WHERE ip='".mysql_rea l_escape_string ($RMADDR,
BTW, the mysql_real_esca pe_string is used any time the data your sticking
into the database might be used for sql injections. This is where they can
mess whith your query to change it to something else and screw up your
database or get its data. I just wrap it around every variable that I use
just incase.
May 11 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3053
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I write some PHP code which should, I think, be able to to auto create the tables. The SQL looks like this:
4
4176
by: Mmm_moo_cows | last post by:
Hi, I'm new to the world of mysql and i'm having alot of trouble with it. All i want to do is create a page with a response form, e.g. name etc and some radio buttons (part of a uni project, but i'm a chemist!) and a submit button to save the data in a database. I installed iss microsoft web server and php and the mysql database. Php works fine, i could write to a text file, and using phpinfo(); it
8
12428
by: W.Davis | last post by:
Group, I'm using ver 5 with winXP. I can access the test database, but can't create a table. I can't create ANY database as I keep getting error 1044 (42000): Access denied for user: ' '@'localhost' to database 'mynewdatabase'. Can you help? TIA, Wade
1
1973
by: Oscar A. Moreno | last post by:
This is a newbie question. I have installed MySQL 4.1.7-Standard in MacOS X (10.3.5). I have ONLY database test. According to the manual there should be TWO. test and mysql. I have re-run mysql_install_db several times with the same result. Can some mysql guru explain or point me to the right page to have this mysql database in my system? Thanks in advance. Oscar A. Moreno oscar.moreno@att.net
0
1573
by: Manzoorul Hassan | last post by:
I just Installed MySQL v4.1.14 and had created a Database (from a script). But I would like to redo the Database portion of it but am not able to drop the Database. If I do a "show database;" I still see the database. But when I look in the data directory, it is not there. Below is my attempt the create / drop the DB: mysql> create database testlink; ERROR 1007 (HY000): Can't create database 'testlink'; database exists mysql> drop...
2
13923
by: Alicia | last post by:
Does anyone know why I am getting a "Syntax error in Create Table statement". I am using Microsoft Access SQL View to enter it. Any other problems I may run into? CREATE TABLE weeks ( weekstart datetime not null primary key, weekend datetime not null )
1
11704
by: Henry16 | last post by:
Hi. Impossible to create a database using MySQL !!! Message : #1006 - Can't create database 'boby'. (errno: 13) I was told : chown mysql.mysql -R /var/lib/mysql chmod 750 -R /var/lib/mysql NOTHING. Absolutly impossible to create a database !!
14
6128
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate places in that hosting.
2
6654
by: Hetal | last post by:
Hi... I am a newbie VB.NET developer and i am looking at working with ADO.NET rather than ADO. In one of our native VB application with ADO, we used to create 1 connection object and that would help us to connect to MS-SQL and MySQL alternatively based on the database type and connection string i provide. So, one connection object was good enough to connect to any of these 2 type of databases. The sample connection string we use to...
0
8737
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9232
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7827
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5905
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4665
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3104
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2036
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.