新手刚学php,关于连接多个数据库的问题

#1 dcb110

$arr=array(
    'driver' => 'mysql',   // 驱动类型
    'host' => 'localhost', // 数据库地址
    'port' => 3306,        // 端口
    'login' => 'root',     // 用户名
    'password' => '123456',      // 密码
    'database' => 'hello',      // 库名称
    'prefix' => '',           // 表前缀
    'persistent' => FALSE,    // 是否使用长链接
);

$dsn_mysql = spClass('db_mysql',$arr, SP_PATH.'/Drivers/mysql.php', TRUE);
$g = spClass('hi');
$g->_db = $dsn_mysql;
$g->findAll();
dump($g);

$this->display('test.html');

运行时出现错误数据库链接错误 : Access denied for user 'ODBC'@'localhost' (using password: NO)

2016-05-26 10:44:23

#2 jake

  Access denied for user 'ODBC'@'localhost' (using password: NO)

这个提示是密码不对或者用户名没有权限。

建议下次先百度,这种错误都是很容易翻译的。

2016-05-26 11:33:42

#3 dcb110

jake 发表于 2016-5-26 11:33
Access denied for user 'ODBC'@'localhost' (using password: NO)

这个提示是密码不对或者用户名没有权 ...
老大,我这不是设置了登录用户名是root,怎么到编译的时候user就成了odbc?还有就是也设置了password为123456咋又变成no了;我把$arr=array{}里面的配置放在index.Php里面的时候连接很正常。

2016-05-28 11:52:00

#4 jake

dcb110 发表于 2016-5-28 11:52
老大,我这不是设置了登录用户名是root,怎么到编译的时候user就成了odbc?还有就是也设置了password为12 ...
呵呵,注意一下,手册http://www.speedphp.com/thread-3794-1-1.html

数据库配置是二维数组,应该是 spClass('db_mysql', array($arr), SP_PATH.'/Drivers/mysql.php', TRUE);

2016-05-29 12:51:24