gpt4 book ai didi

php - 为什么 YII 博客可以很好地连接到 sqlite,但不能连接到 mysql?

转载 作者:行者123 更新时间:2023-11-29 11:33:31 24 4
gpt4 key购买 nike

我已经成功推出了一个使用 Yii 1.1.x 支持 Restful api 的测试博客,我在 mac 中使用 ampps,当我使用 SQLite 数据库时一切正常,我能够正常看到所有 API 响应,我遵循了这个 tutorial并对该页面中的源代码进行了一些修复。

问题是,当我通过

切换到MYSQL数据库时

切换自

'db'=>array(
'connectionString' => '"mysql:host=localhost,dbname=testdrive" Username="root" Password="1234"'),

'db'=>array(
'connectionString'=>'mysql:host=localhost;dbname=test',
'username'=>'deya',
'password'=>'',
//'tablePrefix' => "post",
),

在config/main.php中

然后出现这个错误

Error 500 The table "{{post}}" for active record class "Post" cannot be found in the database.

数据库结构是

enter image description here

如果有用,你可以找到我的测试博客的源代码source code

最佳答案

尝试使用 127.0.0.1 而不是 localhost。另外,您可以在此处发布 models/Post.php 代码的开始吗?

更新:如果您的问题得到解决,请告知我们。代码似乎没问题。用户:deya 是否有权访问 DBName 'test' ?您可以在没有密码的情况下从 phpmyadmin 以 deya 身份登录吗?

其次,确保数据库“test”具有名为“post”的表。如果是这样,请尝试使用 127.0.0.1 作为您的主机

关于php - 为什么 YII 博客可以很好地连接到 sqlite,但不能连接到 mysql?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36998687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com