NYCPHP Meetup

NYPHP.org

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

Jake McGraw jmcgraw1 at gmail.com
Wed Jul 11 09:59:24 EDT 2007


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
>



More information about the talk mailing list