views:

1197

answers:

3

Hi

I am trying to do the Simple Acl controlled Application tutorial in the cakephp cookbook. The idea is :

Making Databases

 CREATE TABLE users (
 id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, username VARCHAR(255) NOT NULL UNIQUE,
 password CHAR(40) NOT NULL,
 group_id INT(11) NOT NULL,
 created DATETIME,
 modified DATETIME
 );


 CREATE TABLE groups (
 id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(100) NOT NULL,
 created DATETIME,
 modified DATETIME
 );


 CREATE TABLE posts (
 id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 user_id INT(11) NOT NULL,
 title VARCHAR(255) NOT NULL,
 body TEXT,
 created DATETIME,
 modified DATETIME
 );

 CREATE TABLE widgets (
 id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
 name VARCHAR(100) NOT NULL,
 part_no VARCHAR(12),
 quantity INT(11)
 );

Then run the cake bake all command, this is when i have the problem :

Welcome to CakePHP v1.2.4.8284 Console
---------------------------------------------------------------
App : app
Path: /Applications/MAMP/htdocs/luis/app
---------------------------------------------------------------
---------------------------------------------------------------
Bake All
---------------------------------------------------------------

Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Applications/MAMP/htdocs/luis/cake/libs/model/datasources/dbo/dbo_mysql.php on line 374

Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/luis/cake/libs/model/datasources/dbo/dbo_mysql.php on line 379

Warning: mysql_get_server_info(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/luis/cake/libs/model/datasources/dbo/dbo_mysql.php on line 387

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /Applications/MAMP/htdocs/luis/cake/libs/model/datasources/dbo/dbo_mysql.php on line 411
Error: Your database does not have any tables.

My database config is like this :

var $default = array(
 'driver' => 'mysql',
 'persistent' => false,
 'host' => 'localhost',
 'port' => 8889,
 'login' => 'root',
 'password' => 'root',
 'database' => 'cake',
);

So i am using the last CakePHP Version (1.2.5), the last Mamp version (1.7.2) running PHP v5... Somebody knows what is the problem ?

+1  A: 

cake can't find the socket.

try making a symbolic link from where your socket is, to where Cake thinks it should be:

ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

cgr
Thank you!I typed the line you gave me in the terminal, but i still have the same error. I am not comfortable with symbolic links, do i have to be in a specific folder when i type it ?
Julien
A: 

Ok i found a way to do it, it might help people who have the same problem : i set a the host to 127.0.0.1 so cake can connect to it. Thanks for help.

Julien
That worked? Sounds strange. localhost and 127.0.0.1 are the same thing. I wonder why it worked
cgr
yes it did... i have no idea why !the weirdest thing to me is that localhost works when i load the cake page but not with the console. So i guess it is that the cake command uses the mac os PHP version and my web page uses the MAMP, which are different, so maybe the Mac OS PHP doesn't understand the "localhost" routing when MAMP is launched.
Julien
+2  A: 

You can also get around using the localhost ip address by doing

var $default = array(
    'driver' => 'mysql',
    'persistent' => false,
    'host' => 'localhost',
    'port' => 8889,
    'login' => 'root',
    'password' => 'root',
    'database' => 'cake',
    'port' => '/Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock',
);

This is because when using a named localhost MYSQL will try and connect through a local socket. By specififying where the socket is via 'port' you change the path it looks for the socket file in. By using 127.0.0.1 or by specifying an IP of any sort you tell MYSQL to connect via http, which does not use the socket at all.

Abba Bryant