CakePHP:无法访问MySQL数据库 [英] CakePHP: Can't access MySQL database

查看:205
本文介绍了CakePHP:无法访问MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚接触CakePHP,只是在配置过程中运行,但是为什么Cake不能访问我的MySQL数据库。蛋糕信息页面说我的tmp目录是可写的,FileEngine正在用于缓存(不知道这是什么意思),并且我的数据库配置文件存在,但是CakePHP无法连接到数据库。



以下是我的设置详情:




  • PHP 5.3(预装在Snow Leopard上) li>
  • MySQL 5.1.40 64位

  • CakePHP 1.2.4.8284



这是我经历的步骤:




  • 创建一个名为cake_blog的MySQL模式

  • 创建一个名为cake_blog_user的MySQL用户

  • 授予cake_blog_user对cake_blog @ localhost和cake_blog @%的适当权限

  • 复制database.php.default文件



下面是来自database.php的相关配置数据:

 
var $ default = array(
'driver'=>'mysql',
'persistent'=> false,
'host'=>'localhost',
'login'=>'cake_blog_user',
'password'=>'cake_blog_password',
'database'=>'cake_blog'
'prefix'=>'',
);

我缺少这里的东西吗?我还应该提到,如果我在测试数据库连接之前插入 echo mysql_error(); 到/cake/libs/view/pages/home.ctp文件中,显示的错误是没有这样的文件或目录。我不知道它在说什么文件或目录。



谢谢!

解决方案

如果是套接字,只需编辑/etc/php.ini以反映以下



  pdo_mysql.default_socket = /tmp/mysql.sock 

  mysql.default_socket = /tmp/mysql.sock 


I'm new to CakePHP and am just running through the configuration process, but am stumped why Cake can't access my MySQL database. The Cake info page says my tmp directory is writable, the FileEngine is being used for caching (don't know what this means), and my database configuration file is present, but that CakePHP cannot connect to the database.

Here are my setup details:

  • PHP 5.3 (pre-installed on Snow Leopard)
  • MySQL 5.1.40 64-bit
  • CakePHP 1.2.4.8284

Here are the steps I went through:

  • Created a MySQL schema called cake_blog
  • Created a MySQL user called cake_blog_user
  • Granted cake_blog_user the appropriate permissions on cake_blog@localhost and cake_blog@%
  • Copied the database.php.default file to database.php and edited the database connection details as appropriate

Here is the relevant configuration data from database.php:

    var $default = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'cake_blog_user',
        'password' => 'cake_blog_password',
        'database' => 'cake_blog',
        'prefix' => '',
    );

Am I missing something here? I should also mention that if I insert an echo mysql_error(); into the /cake/libs/view/pages/home.ctp file right before it tests the database connection, the error displayed is "No such file or directory." I have no idea what file or directory it's talking about.

Thanks!

解决方案

If it is the socket, just edit /etc/php.ini to reflect the following

pdo_mysql.default_socket=/tmp/mysql.sock

and

mysql.default_socket = /tmp/mysql.sock

这篇关于CakePHP:无法访问MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆