943,931 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 4525
  • PHP RSS
Sep 7th, 2004
0

"preg_match" For What purpose this command use?

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
qadeer is offline Offline
2 posts
since Sep 2004
Sep 8th, 2004
0

Re: "preg_match" For What purpose this command use?

http://www.php.net/preg_match will answer your question.
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: databases thatcan be used with php!!!
Next Thread in PHP Forum Timeline: I need an ide for php





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC