Getting numerous results in error logs like the ones below. All tables in the database are innodb and, as far as any interaction with these tables, all pdo with prepared statements.
As I said, all errors are almost identical to those listed below, but occur on several different pages. Regardless of the page, the ALWAYS error line points to the point at which I run the new statement ... for example, $stmt = $db->prepare("........ The statements themselves work fine, without errors, so I'm a little puzzled by what causes this.
A few errors like this for different pages:
[25-Sep-2014 10:19:09 America / Chicago] Failed to connect to the database: SQLSTATE [HY000] [2002] Resource temporarily unavailable [25-Sep-2014 10:19:09 America / Chicago] PHP Fatal error : call a member function Prepare () for a non-object in / home / test / public _html / add_log.php on line 28
Example stmt error points to - in this case, the string $stmt = $db->prepare(" . It always points to a line starting with a new prepared statement.
$stmt = $db->prepare(" SELECT accounts.account_id, computers.computer_id, computers.status, users.user_id FROM accounts LEFT JOIN computers ON computers.account_id = accounts.account_id AND computers.computer_uid = :computer_uid LEFT JOIN users ON users.computer_id = computers.computer_id AND users.username = :username WHERE accounts.account_key = :account_key "); //bindings $binding = array( 'account_key' => $_POST['account_key'], 'computer_uid' => $_POST['computer_uid'], 'username' => $_POST['username'] ); $stmt->execute($binding); //result (can only be one or none) $result = $stmt->fetch(PDO::FETCH_ASSOC);
connect script:
<?php if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly'); // db config $db_host = 'localhost'; $db_database = '*******'; $db_user = '*******'; $db_pass = '*******'; //db connection try { $db = new PDO("mysql:host=$db_host;dbname=$db_database;charset=utf8", $db_user, $db_pass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_PERSISTENT => true)); } catch(PDOException $e) { error_log("Failed to connect to database: ".$e->getMessage()); } ?>
What crossed my mind:
This particular script works a lot ... sometimes it can be called several times in one second.
On this site I use the same format for all my prepared statements ... $ stmt = ... $ result or $ results = ... I do not close the cursor, however, it is not required from my research, since the driver is MySQL, and this is done automatically.
I set PDO :: ATTR_PERSISTENT to true in my connection settings - will this have anything to do with this error?
What happens to all these errors? Is anyone
EDIT - Additional Information:
- I changed localhost to 127.0.0.1 explicitly
- I have disabled persistent connections / false
Since the above, the error has changed to SQLSTATE[HY000] [2002] Connection timed out . Is this really a problem with the person / computer connecting to "me" or is it really a problem with my / db server?
EDIT 2:
Is it possible that my use of $_SERVER['DOCUMENT_ROOT'] might cause the problem? Since this file "hit" so often, it also requires a script connection as often on the line below. I need a script connection, as follows on each page:
$ _SERVER ['DOCUMENT_ROOT'] required. '/custom/functions/connect.php';