| | |
"preg_match" For What purpose this command use?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
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
<?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
•
•
Join Date: Jul 2004
Posts: 234
Reputation:
Solved Threads: 8
http://www.php.net/preg_match will answer your question.
![]() |
Similar Threads
- Writting a "command promt" or "Shell".. dealing with directories ! (C++)
- Not able to access "Run" command or Startup (Windows NT / 2000 / XP)
- command.Parameters.AddWithValue("@number", TextBox1.Text) (VB.NET)
- google "keyword" question (Search Engine Optimization)
- "Talking" to Command Prompt (C)
- DOS "ROUTE" command (Visual Basic 4 / 5 / 6)
Other Threads in the PHP Forum
- Previous Thread: databases thatcan be used with php!!!
- Next Thread: I need an ide for php
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





