This command working but i do't understand it ??? i am writing funtion in which it using please guid me..

<?php
$dbHost="localhost";
$dbLogin="root";
$dbPassword="123";
$dbName="test12";
$query="";
$error="";
$mySqlError="";
$connect = mysql_connect( $dbHost, $dbLogin, $dbPassword ) ;
if ( !mysql_select_db( $dbName ) )
{
return "<p>Error: Database[ $dbName ] could not be located p>" ;
}
$fp = fopen ("database2.txt", "r") ;
while (!feof ($fp))
{
$query="";
$error="";
$buff = fgets($fp, 1000);


if ( preg_match( "/(DROP TABLE)/", $buff ) )
{
$query = substr( $buff, 0, strlen( $buff ) - 2 ) ;
$query = stripslashes( $query ) ;
$res = mysql_query( $query, $connect ) ;
$mySqlError .=  mysql_error() ;
}


if ( preg_match( "/(CREATE TABLE)/", $buff ) )
{
$query .= $buff ;
if ( !preg_match( "/\) TYPE=MyISAM/", $buff ) )
{
while ( $buff = fgets( $fp, 500 ) )
{
if ( preg_match( "/\) TYPE=MyISAM/", $buff ) ){ break 1 ; }
$query .= $buff ;
}
if ( !preg_match( "/\) TYPE=MyISAM/", $query ) )
$query = "$query);" ;
}
$query = stripslashes( $query ) ;
$res = mysql_query( $query, $connect ) ;
$mySqlError .=  mysql_error() ;
}


if ( preg_match( "/(INSERT INTO)/", $buff ) )
{
$query = substr( $buff, 0, strlen( $buff ) - 2 ) ;
$query = stripslashes( $query ) ;
$res = mysql_query( $query, $connect ) ;
$mySqlError .=  mysql_error() ;
}
}
fclose( $fp ) ;
mysql_close( $connect ) ;
if ( $mySqlError )
{
$error = "<p>Error: Following database error(s) were generated:<br>$mySqlError<p>" ;
}
return $error ;



?>

With Best Regards
Qadeer Ahmad

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.