NYCPHP Meetup

NYPHP.org

[nycphp-talk] Creating a MySQL DataBase using/through php script. Can anybody help??

Jon Baer jonbaer at jonbaer.com
Wed Jul 11 10:54:54 EDT 2007


You would also need to set special GRANT privileges for user "paul".

http://dev.mysql.com/doc/refman/5.1/en/create-database.html
http://dev.mysql.com/doc/refman/5.1/en/grant.html

Also of note ...

-snip-
If you manually create a directory under the data directory (for  
example, with mkdir), the server considers it a database directory  
and it shows up in the output of SHOW DATABASES.
-snip-

- Jon

On Jul 11, 2007, at 9:59 AM, Jake McGraw wrote:

> Ah, you may need to modify the @mysql_query() command like so:
>
> @mysql_query('CREATE DATABASE '.$_REQUEST['db']);
>
> So that the final submitted query looks like (for $_REQUEST['db'] =
> 'myDatabase'):
>
> CREATE DATABASE myDatabase
>
> Whereas before you were issuing the query:
>
> myDatabase
>
> Which makes no sense and would have resulted in an error, except that
> you were using an the error control (@) operator. See
> http://us2.php.net/@ for more information.
>
> - jake
>
> On 7/11/07, PaulCheung <paulcheung at tiscali.co.uk> wrote:
>> Can anybody see what I am doing wrong?
>>
>> Using Mike McGrath's book "PHP 5 in easy steps" I have been trying  
>> to get
>> both his textbook example on page 144 "Creating a database" and  
>> the example
>> from the www.ineasysteps.com website to work. Not being able to  
>> get either
>> the textbook example or "create_db.php" to work and in pure  
>> frustration I
>> contacted the publishers and got a reply from Mike and implemented  
>> his
>> suggested changes; Using the MySQL "show databases;" line command  
>> to verify
>> database creation, it shows no database was created. Here is the code
>> including the Mike's suggested changes. It all appears to work on the
>> surface; but you will need to check a little deeper under the  
>> surface to see
>> what I mean.
>>
>> Paul
>>
>> <!-- example for PHP 5.0.0 final release -->
>> <?php
>> $conn = @mysql_connect( "localhost", "paul", "enter" )
>>  or die( "Sorry - could not connect to MySQL" );
>>
>> $rs1 = @mysql_query( $_REQUEST['db'] );
>> $rs2=  @mysql_list_dbs($conn);
>>
>> $list = "";
>>
>> for( $row=0; $row < mysql_num_rows( $rs2 ); $row++ )
>> {
>>   $list .= mysql_tablename( $rs2, $row ) . " | ";
>> }
>> ?>
>>
>> <html>
>>  <head>
>>   <title>Creating databases</title>
>>  </head>
>>  <body>
>>  <form action="<?php echo( $_SERVER['PHP_SELF'] ); ?> "  
>> method="post">
>>
>>  Current databases: <?php echo( $list ); ?>
>>  <hr>
>>  Name:<input type = "text" name = "db">
>>  <input type = "submit" value = "Create database">
>>  </form>
>>  </body>
>> </html>
>> _______________________________________________
>> New York PHP Community Talk Mailing List
>> http://lists.nyphp.org/mailman/listinfo/talk
>>
>> NYPHPCon 2006 Presentations Online
>> http://www.nyphpcon.com
>>
>> Show Your Participation in New York PHP
>> http://www.nyphp.org/show_participation.php
>>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070711/82f40b0b/attachment.html>


More information about the talk mailing list