Test Ar-PHP Functionality Online

header line!
Test PHP Function










Ar-PHP Manual

method getWhereCondition [line 316]

string getWhereCondition( string $arg)

Build WHERE section of the SQL statement using defind lex's rules, search mode [AND | OR], and handle also phrases (inclosed by "") using normal LIKE condition to match it as it is.



Tags:

return:  The WHERE section in SQL statement (MySQL database engine format)
author:  Khaled Al-Sham'aa <khaled@ar-php.org>
access:  public


Parameters:

string   $arg   String that user search for in the database table

Example
  1.      include('./I18N/Arabic.php');
  2.      $obj new I18N_Arabic('Query');
  3.  
  4.      $dbuser 'root';
  5.      $dbpwd '';
  6.      $dbname 'test';
  7.  
  8.      try {
  9.          $dbh new PDO('mysql:host=localhost;dbname='.$dbname$dbuser$dbpwd);
  10.  
  11.          // Set the error reporting attribute
  12.          $dbh->setAttribute(PDO::ATTR_ERRMODEPDO::ERRMODE_EXCEPTION);
  13.  
  14.          $dbh->exec("SET NAMES 'utf8'");
  15.  
  16.          if ($_GET['keyword'!= ''{
  17.              $keyword @$_GET['keyword'];
  18.              $keyword = str_replace('\"''"'$keyword);
  19.  
  20.              $obj->setStrFields('headline');
  21.              $obj->setMode($_GET['mode']);
  22.  
  23.              $strCondition $Arabic->getWhereCondition($keyword);
  24.          else {
  25.              $strCondition '1';
  26.          }
  27.  
  28.          $StrSQL "SELECT `headline` FROM `aljazeera` WHERE $strCondition";
  29.  
  30.          $i 0;
  31.          foreach ($dbh->query($StrSQLas $row{
  32.              $headline $row['headline'];
  33.              $i++;
  34.              if ($i == 0{
  35.                  $bg "#f0f0f0";
  36.              else {
  37.                  $bg "#ffffff";
  38.              }
  39.              echo "<tr bgcolor=\"$bg\"><td>$headline</td></tr>";
  40.          }
  41.  
  42.          // Close the databse connection
  43.          $dbh null;
  44.  
  45.      catch (PDOException $e{
  46.          echo $e->getMessage();
  47.      }
Popular
Recent
Links
Ads!
footer line!

No Software Patents! General Public License

Home | Twitter | Blog | Contact

Copyright © 2006 - 2016 Khaled Al-Sham'aa