- Impact
- 8
function find_email($e){
include('config.php');
$connection = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$connection);
$sql = "SELECT id from customers where email = '" . $e . "'";
$result = mysql_query($sql) or die('error, query failed');
$num = mysql_num_rows($result);
mysql_close($connection);
$i=0;
$id = 0;
if($num > 0){
while ($i < $num){
$id = mysql_result($result,$i,"id");
$i++;
}
}
return $id;
}
function products($id,$para){
echo $ids;
require('config.php');
require_once('ps_pagination.php');
$connection = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname,$connection);
$sql = "SELECT name, code, public, image from products where online = 1 and categoryid in (" . $id . ") order by id desc";
$q = 'category='.$para;
mysql_close($connection);
$pager = new PS_Pagination($connection, $sql, 10, 5,$q);
$rs = $pager->paginate();
$i = 0;
$foundEntries = false;
if(strlen($rs) > 0){
$foundEntries = true;
while($row = mysql_fetch_assoc($rs)){
echo '<div class="productbrief"><div class="productbriefimage"><a href="details.php?public=';
echo $row['public'] . '">';
if(strlen($row['image']) > 0){
echo '<img src="data/images/' . $row['image'] . '" width="70" />';
}
else{
echo '<img src="images/noimage.jpg" width="70" />';
}
echo '</a></div><div class="productbrieftext"><em><a href="details.php?public=' . $row['public'] . '">' . $row['name'] . '</a></em><br /><em>Product #:</em> ' . $row['code'] . '</div><div class="clr"></div></div>';
if((($i+1) % 4) == 0){
echo '<div class="clr"></div>';
}
$i++;
}
echo '<div class="clr"></div>';
echo '<div class="pager">' . $pager->renderFullNav() . '</div>';
}
return $foundEntries;
}
The error you receive is not about the single database it is about the user. If you have 2 databases that the same user can access this would result in the same issue.
I notice from your code snippets that these 2 functions call the database and make a new connection. This is very ineeficient and you will find the script making a fresh connection to the DB quite a lot. For example if you called each of those functions 5 times each on the page that is 10 database connections just for the 1 page. Now multiply that by the amount of visitors and it grows exponentially.
You should be opening the database and leaving the 1 connection open until the script has finished with the database completely.