Asked  7 Months ago    Answers:  5   Viewed   26 times

As you can see I have a problem on a database connection. It gives me this error:

...is blocked because of many connection errors

I searched some answers but I couldn't solve my problem.

I don't know if I gave all the information that you need, so if you need something else, just tell me. I have a database connection from different computers and I had a user created to access the database but it had % in the hosts row, so I wanted to change it with an IP address for security issues and it gave me this error so now I'm stuck.

 Answers

56

MySQL blocks clients which error made while connecting to protect MySQL from malformed client.

So first, you need to find what sort of error is....

You might check MySQL error log in data directory. (typically hostname.err)

Or, you can increase max_connect_errors (what is current value?) maximum value depends on architecture. on 32 bit, 4294967295. 18446744073709547520 for 64 bit. (Manual)

mysql> SET GLOBAL max_connect_errors = 100000000;

But this is not real solution if error is frequently occurred.

FLUSH HOSTS can help you to eliminate blocked host right now.

mysql> FLUSH HOSTS;

If want to run from outside mysql console then use mysqladmin command:

# mysqladmin flush-hosts
Wednesday, March 31, 2021
 
subroutines
answered 7 Months ago
10

You don't need to escape your variables in a prepared statement, instead you should bind your variables before executing the statement. Also the column names should be inside ` marks.

$stmt = $dbConnectionW->prepare("UPDATE members SET 
                      `fname`=?,
                      `sname`=?,
                      `gender`=?,
                      `nationality`=?,
                      `year`=?,
                      `dep1`=?,
                      `dep2`=?,
                      `f_pos`=?,
                      `f_region`=?,
                      `exp_comp`=?,
                      `exp_dep`=?,
                      `shareinfo`=?,
                      `interest`=?,
                      `userconfirm`=?
                          WHERE `confirmcode`=?");
$stmt->bind_param('ssssissssssssis',$_POST['fname'],$_POST['sname'],$_POST['gender'],...);          
$stmt->execute();

I haven't included all the bound parameters for brevity.

Hope this helps.

Wednesday, March 31, 2021
 
hjalpmig
answered 7 Months ago
88

Delete your other question, ok?

The problem is you loop through $_SESSION and use the same name value each time. You need to create an array of your inputs. Here is an example:

<?php
echo '<h3>Your Order</h3>';
$current_url = base64_encode($url='http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  if(isset($_SESSION['products'])){
     echo '<ol>';
     echo '<form action="checkout_with_us.php" method="POST">';
     $total = 0;
     $cart_items = 0;

        foreach($_SESSION['products'] as $cart_itm){
           $product_code = $cart_itm['code'];
           $results = $mysqli->query("SELECT product_name,product_desc,price FROM products WHERE product_code='$product_code' LIMIT 1");
             $obj = $results->fetch_object();
                echo '<li>';
                echo 'Price: '.$currency.$obj->price;
                echo '<h4>'.$obj->product_name.'(Code: '.$product_code.')</h4>';
                echo 'Qty: '.$cart_itm['qty'];
                echo '</li>';

                   $subtotal = ($cart_itm['price'] * $cart_itm['qty']);
                     $total = ($total + $subtotal);
                     $cart_items++;
                       echo '<input type="hidden" name="product['.$product_code.'][item_name]" value="'.$obj->product_name.'">';
                       echo '<input type="hidden" name="product['.$product_code.'][item_desc]" value="'.$obj->product_desc.'">';
                       echo '<input type="hidden" name="product['.$product_code.'][item_qty]" value="'.$cart_itm["qty"].'">';
                       echo '<input type="hidden" name="product['.$product_code.'][item_code]" value="'.$product_code.'">';     
                }
                    echo '<strong>Sub Total: '.$currency.$total.'</strong>';
                    echo '<input type="hidden" name="product['.$product_code.'][price]" value="'.$total.'">';
                    echo '</ol>';   
                    }

//Here is the information of the customer
echo 'Firstname: <input type="text" name="firstname"><br />';
echo 'Lastname: <input type="text" name="lastname"><br />';
echo 'Email: <input type="text" name="email"><br />';
echo '<input type="submit" value="Send Step">';

echo '</form>';
?>

You can catch this by looping in your product array:

<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];

$conn = mysqli_connect('localhost','root','','sampsix')or die('Could not connect');

foreach($_POST['product'] as $product)
{
    $order_name = $product['item_name'];
    $order_code = $product['item_code'];
    $order_qty = $product['item_qty'];
    $sub_total = $product['price'];

    $query = "INSERT INTO `sampsix`.`orders`(`firstname`,`lastname`,`email`,`OrderName`,`OrderCode`,`OrderQty`,`SubTotal`) VALUES('$firstname','$lastname','$email','$order_name','$order_code','$order_qty','$sub_total')";
    mysqli_query($conn,$query);
}



mysqli_close($conn);

header('Location: checkout.php');
?>

I don't know what the purpose is of the table orders but with my example the products will be added to this table with the same firstname, lastname, etc.

Saturday, May 29, 2021
 
Ula
answered 5 Months ago
Ula
28

One assumes that you mean cause the thread to stop its current operation and throw an InterruptedException? A thread interrupt in Java is just a flag. You can call interrupt() just fine on a BLOCKED thread and that flag will be seen next time code checks for it.

The principle problem with implementing such a functionality is, how is a keyword (synchronized) supposed to throw an exception? InterruptedException is a checked exception, it would not be a useful exercise to have to declare every synchronized method (and block) in the language with throws InterruptedException!

An interrupt is a communication tool, it's generally for letting a thread know about a system state it needs to check on. The name is a legacy carry over/upward from flags set within hardware to let microprocessors know about a particular state (such as new values set on some input pins) that needs to be examined. Do not read too much into the name "interrupt" and think it's meant to be a tool for breaking the flow of the program within another thread. It is not. Hence even the methods that do throw an exception declare it as checked, the other thread is free to ignore it and resume waiting if it wants. Being able to arbitrarily break another thread's BLOCKED state would break the program flow, which is not the purpose.

Thursday, August 26, 2021
 
Sugrue
answered 2 Months ago
22

After about 3 hours of horrible debugging I now know what's going on. I have a service-level method that I also have an "around" advice on. The service-level method is annotated with @Transactional(readOnly=true), however, I have another service in my advice that was annotated with @Transactional(readOnly=false).

My aspect (or advice) is using the same DAO objects as my normal service-layer, so when I called sessionFactory.getCurrenctSession() it's giving me back the session that was created for my Read-Only Service-level method. Now, I have to re-architect.

Monday, September 6, 2021
 
RakshithAnand
answered 1 Month ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :