Anda di halaman 1dari 4

<?php //load plain/text data into $dataTokenCollection as a string.

$dataTokenCollection=file_get_contents(__FILE__,null,null,__COMPILER_HALT_OFFSE T__); list($sqlDataQueries,$htmlData,$htmlData2,$cssData,$htmlView,$htmlInsertDataPage ,$htmlInsertDataResult)=explode('======data separator======',$dataTokenCollectio n); $sqlData=explode('-- ---------sql separator----------',$sqlDataQueries);

mysql_connect('localhost','root',''); mysql_select_db('arabic_test'); mysql_set_charset('utf8'); $action=isset($_POST['action'])?$_POST['action']:(isset($_GET['action'])?$_GET[' action']:''); if($action=='Create Table') { mysql_query($sqlData[0]) or die(mysql_error()); mysql_query($sqlData[1]) or die(mysql_error()); mysql_query($sqlData[2]) or die(mysql_error()); //echo "Table created successfully!\n<br />\n<a href=\"{$_SERVER['PHP_SE LF']}\">Return to main page.</a>"; eval($htmlData2); exit; } if($action=='Insert Data') { if(!isset($_POST['subaction'])) { eval($htmlInsertDataPage); }else if($_POST['subaction']=='submit'){ if(!isset($_POST[stringToSave])){echo 'No data sent!';exit;} $str=mysql_real_escape_string($_POST[stringToSave]); $sql="INSERT INTO `arabic_test_table1` (`id`, `arabic_text`) VALUES (NULL,'$str')"; $result=mysql_query($sql) or die(mysql_error()); $num=mysql_affected_rows(); $addEntryResult=""; if($num==1) { $addEntryResult.="Successfully added your post to the database!\ n<br />\n"; }else if($num>1){ $addEntryResult.="Successfully added your <em>posts</em> to the database!\n<br />\n"; }else{ $addEntryResult.="An unknown error occured while trying to add y our post to the database.\n<br />\n"; } eval($htmlInsertDataResult); }//else exit; } if(mysql_num_rows(mysql_query("SHOW TABLES LIKE 'arabic_test_table1'"))==0) { eval($htmlData);//echos the results of the evaluated PHP code

}else{ $result=mysql_query('SHOW COLUMNS FROM `arabic_test_table1`'); $outTable=""; $outTable.='<table border="1"><tr>'; while($row=mysql_fetch_assoc($result)) { $outTable.='<th>'.htmlentities($row['Field']).'</th>'; }//while $outTable.='</tr>'; $result=mysql_query('SELECT * FROM `arabic_test_table1`'); while($row=mysql_fetch_row($result)) { $outTable.='<tr>'; foreach($row as $column) { $outTable.='<td>'.htmlentities($column,ENT_QUOTES,'UTF-8').'</td >'; } $outTable.='</tr>'; }//while $outTable.="</table>\n"; eval($htmlView);//echos the results of the evaluated PHP code }//else

//Everything after the halt complier will be ignored by PHP //But in this case we will have PHP open itself in plain/text mode later to grab this data __halt_compiler(); SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- ---------sql separator---------CREATE TABLE IF NOT EXISTS `arabic_test_table1` ( `id` int(10) unsigned NOT NULL auto_increment, `arabic_text` text character set utf8 NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `arabic_text` (`arabic_text`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2; -- ---------sql separator---------INSERT INTO `arabic_test_table1` (`id`, `arabic_text`) VALUES (1, ' '); ======data separator====== ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ultimater's Arabic Test Database Example</title> <link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="imag e/x-icon"/> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST"> <input type="submit" name="action" value="Create Table" /> </form> </body> </html> <?php

======data separator====== ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ultimater's Arabic Test Database Example</title> <link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="imag e/x-icon"/> </head> <body> <?php echo "Table created successfully!\n<br />\n<a href=\"{$_SERVER['PHP_SELF']}\">Re turn to main page.</a>"; ?> </form> </body> </html> <?php ======data separator====== body { margin: 0; padding: 1em; font: medium arial, helvetica, sans-serif; } table { border-collapse: collapse; border: solid 2px black; font-weight: normal; font-size: small; margin: 0.25em 0 0.5em 0; } td,th { border: solid 1px black; padding: 0.1em 0.25em; } th { background-color: #ccc; } h2 { /* CSS Horizontal Rule */ margin: 1em 0 0.5em 0; border-top: solid 2px black; padding-top: 1em; } li { font-weight: bold; font-size: large; margin-top: 0.5em; } ======data separator====== ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ultimater's Arabic Test Database Example</title> <link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="imag

e/x-icon"/> <style type="text/css"><?php echo $cssData; ?></style> </head> <body> <h2>Table `arabic_test_table1`:</h2> <?php echo $outTable; ?> <br /> <a href="<?php echo $_SERVER['PHP_SELF'];?>?action=Insert Data">Insert Data</a> </body> </html> <?php ======data separator====== ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ultimater's Arabic Test Database Example</title> <link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="imag e/x-icon"/> <style type="text/css"><?php echo $cssData; ?></style> </head> <body> <h2>Insert Data into `arabic_test_table1`:</h2> <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST"> <input type="hidden" name="action" value="Insert Data" /> <input type="hidden" name="subaction" value="submit" /> <input type="text" name="stringToSave" value="" /> <input type="submit" value="Insert!" /> </form> <?php echo "<a href=\"{$_SERVER['PHP_SELF']}\">Return to main page.</a>"; ?> </body> </html> <?php ======data separator====== ?> <!doctype html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Ultimater's Arabic Test Database Example</title> <link rel="icon" href="http://www.ultimater.net/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="http://www.ultimater.net/favicon.ico" type="imag e/x-icon"/> <style type="text/css"><?php echo $cssData; ?></style> </head> <body> <?php echo $addEntryResult; ?> <?php echo "<a href=\"{$_SERVER['PHP_SELF']}\">Return to main page.</a>"; ?> </body> </html> <?php

Anda mungkin juga menyukai