NYCPHP Meetup

NYPHP.org

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

PaulCheung paulcheung at tiscali.co.uk
Wed Jul 11 09:43:25 EDT 2007


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> 



More information about the talk mailing list