Example Name: SearchProducts.php
Language: PHP
Version: 1.0.0
Code:
<?php
class SearchProducts {
function SearchProducts() { /* constructor */
$this->methodTable = array(
'getSearchResult' => array(
'description' => 'Searches the database and returns a result.',
'access' => 'remote',
'arguments' => array('search')
)
);
}
function getSearchResult($search) {
if (!$link = mysql_pconnect('localhost', 'myUsername', 'myPassword'))
return mysql_error();
if (!mysql_select_db('Northwind', $link)) return mysql_error();
$query = 'SELECT ProductName, UnitPrice, QuantityPerUnit FROM Products';
$query .= (!empty($search)) ? " WHERE ProductName LIKE '%$search%'" : '';
if (!($result = mysql_query($query, $link))) return mysql_error();
return $result;
}
}
?>
Download code text
Download chapter example files