1
我試圖在我的應用程序中實現Zend Db。使用Zend Db連接到數據庫
目前,我正在使用會話管理器。
DB是發起這樣:
use Zend\Config\Config;
$config = new Zend\Config\Config(include ROOT . DS . 'config' . DS . 'config.php');
$database = new Zend\Db\Adapter\Adapter($config->database->toArray());
雖然我的配置文件看起來像這樣:
return array(
'sie_product_name' => 'product name',
'salt' => 'salt',
'max_session_time' => '3600',
'database' => array(
'driver' => 'MYSQLI',
'params' => array(
'host' => 'localhost',
'username' => 'username',
'password' => 'password',
'dbname' => 'dbname'
)
)
);
當我試圖執行一個選擇:
$sql = new Sql($this->database);
$query = $sql->select();
$query->from('sessions');
$query->columns(array('sessionid'));
$query->where(array('sessionid' => $sessionId));
$stmt = $sql->prepareStatementForSqlObject($query);
$result = $stmt->execute();
我出現錯誤:
Connect Error: SQLSTATE[HY000] [1045] Access denied for user ''@'localhost' (using password: NO)
很酷,這是一個連接錯誤......但連接丟失或者我應該說什麼,證書在哪裏丟失?讓我們來看看數據庫對象...
Zend\Db\Adapter\Adapter Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Mysqli\Mysqli Object
(
[connection:protected] => Zend\Db\Adapter\Driver\Mysqli\Connection Object
(
[driver:protected] => Zend\Db\Adapter\Driver\Mysqli\Mysqli Object
*RECURSION*
[connectionParameters:protected] => Array
(
[driver] => MYSQLI
[params] => Array
(
[host] => localhost
[username] => username
[password] => password
[dbname] => dbname
)
)
[resource:protected] => mysqli Object
(
[affected_rows] =>
[client_info] => mysqlnd 5.0.10 - 20111026 - $Id: b0b3b15c693b7f6aeb3aa66b646fee339f175e39 $
[client_version] => 50010
[connect_errno] => 1045
[connect_error] => Access denied for user ''@'localhost' (using password: NO)
[errno] => 1045
[error] => Access denied for user ''@'localhost' (using password: NO)
[error_list] =>
[field_count] =>
[host_info] =>
[info] =>
[insert_id] =>
[server_info] =>
[server_version] =>
[stat] =>
[sqlstate] =>
[protocol_version] =>
[thread_id] =>
[warning_count] =>
)
[inTransaction:protected] =>
)
[statementPrototype:protected] => Zend\Db\Adapter\Driver\Mysqli\Statement Object
(
[mysqli:protected] =>
[driver:protected] => Zend\Db\Adapter\Driver\Mysqli\Mysqli Object
*RECURSION*
[sql:protected] =>
[parameterContainer:protected] =>
[resource:protected] =>
[isPrepared:protected] =>
[bufferResults:protected] =>
)
[resultPrototype:protected] => Zend\Db\Adapter\Driver\Mysqli\Result Object
(
[resource:protected] =>
[isBuffered:protected] =>
[position:protected] => 0
[numberOfRows:protected] => -1
[currentComplete:protected] =>
[nextComplete:protected] =>
[currentData:protected] =>
[statementBindValues:protected] => Array
(
[keys] =>
[values] => Array
(
)
)
[generatedValue:protected] =>
)
[options:protected] => Array
(
[buffer_results] =>
)
)
[platform:protected] => Zend\Db\Adapter\Platform\Mysql Object
(
)
[queryResultSetPrototype:protected] => Zend\Db\ResultSet\ResultSet Object
(
[allowedReturnTypes:protected] => Array
(
[0] => arrayobject
[1] => array
)
[arrayObjectPrototype:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
[returnType:protected] => arrayobject
[buffer:protected] =>
[count:protected] =>
[dataSource:protected] =>
[fieldCount:protected] =>
[position:protected] =>
)
[lastPreparedStatement:protected] =>
)
看起來像被設置連接參數 - 太棒了!但它仍然沒有連接。
問這樣的問題之前,請先閱讀Zend的\ DB的文檔! – markus