Hi,
Саша Стаменковић wrote:
>> [...]
>> So there must be something wrong in your code. E.g. a logical error (wrong
>> usage).
>
> I'm pretty sure it's one connection too, but for quoting value,
> does Zend_Db_Adapter contacts mysql server in order to get some
> info about how to quote it?
>
> I'm asking because I see quote method in exception trace:
>
> 2010-05-20T10:08:40+02:00 ERR (3): exception
> 'Zend_Db_Adapter_Mysqli_Exception'
> with message 'User *** already has more than 'max_user_connections' active
> connections'
> in Zend/Db/Adapter/Mysqli.php:333
> Stack trace:
> #0 Zend/Db/Adapter/Abstract.php(832): Zend_Db_Adapter_Mysqli->_connect()
> #1 Zend/Db/Adapter/Abstract.php(902): Zend_Db_Adapter_Abstract->quote('582',
> NULL)
> #2 Zend/Db/Select.php(1000): Zend_Db_Adapter_Abstract->quoteInto('table...',
> '582', NULL)
> #3 Zend/Db/Select.php(475): Zend_Db_Select->_where('table...', '582', NULL,
> true)
> ...
When you create a new Zend_Db_Table instance, no DB connection is used.
So the following code won't establish any DB connections:
---
<?php
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'user',
'password' => 'password',
'dbname' => 'dbname'
));
Zend_Db_Table::setDefaultAdapter($db);
$table = new Zend_Db_Table('tableName');
---
In the moment you do something with $table, Zend_Db_Table will do the "setup"
by calling "$this->_setupPrimaryKey()".
Keep in mind, that the used quoteInto() methods comes from the adapter. There
is no $table->quoteInto() method. You will do something like
---
$value = '2010-05-24';
$adapter = $table->getAdapter();
$quotedValue = $adapter->quoteInto('WHERE date < ?', $value);
---
The quoteInto() method will use the quote() method internally, which will call
_connect() method.
But this method will only establish a connection, if this adapter hasn't yet
established one:
>From Zend\Db\Adapter\Mysqli.php:
protected function _connect()
{
if ($this->_connection) {
return;
}
// [...]
So again, Zend_Db_* itself cannot be the problem. This component will reuse one
connection across all instances where it's possible.
The stack trace you see will just tell you, that I wasn't able to make a
connection. Now, after I showed to you, that when you use a table/adapter, it
will establish a connection, if the used adapter hasn't yet establish one, it
shouldn't be surprising, that a quoteInto() call was the start point. You
understand?
The problem might be (if there aren't too many parallel requests to your
application as I wrote some days ago), that you are using Zend_Db_* the wrong
way. E.g. forcing new connection etc. - nobody can tell you in detail, without
knowing your code, what the problem in your case is ;-)
How you could find the problem should be easy: Run your code locally in a
debugger and keep an eye on the mysqld query log. If you see more than one
Time Id Command Argument
100524 17:15:11 1 Connect u...@localhost on tableName
you know there is something wrong in your code. Then running your request step
by step in a debugger will tell you exactly, which code is causing the problem.
--
Regards,
Thomas