Welcome Guest, Not a member yet? Register   Sign In
[DB] Problem connecting to database
#1

[eluser]blackdog[/eluser]
Hello everyone, i'm trying to follow the tutorials for learning the basics of CI but i got a problem in connecting to the database.
I searched the forum, found a topic with similar problem but no one seems to have my same configuration, plus it's months old and no one replied the last question, so seemed right to open a new one.

I'm working on a Mac with MAMP as a server and mysql as db.

A friend of mine taught me how to configure a virtual host "to work more professionally".

So i have CI and the wannabe-test-app in:

users/blackdog/[...]/igniter_test/

while the database is under

[...?]/applications/mamp/db/mysql/igniter_test

when i come up to configuring the database.php i simply change the name, but nothing happens. i change the username parameter to:

$db['default']['username'] = "root@localhost";

because in phpmyadmin front page it says: "User: root@localhost", but still i get an error in selecting the db.
I thought that maybe was the "_" causing problems, so i changed the db_name from "igniter_test" to "test", because i had created one in the past.
It conncets to it

BUT

if i change the name of the original db "igniter_test" to "igniter" or "igniterTest", i still get an error, so i don't think it's the underscore.

I think it's something with the paths or romething like that, caused by the fact that CI libraries are in the virtual host folder and the db under the localhost.
In fact if i try to work with the "test" db already exsiting, i manage to connect to the table with the scaffolding

BUT

when i try using to add a record with it, i get an error

Not Found
The requested URL //spublic/index.php/blog/database/add was not found on this server.
Apache/2.0.59 (Unix) PHP/5.2.3 DAV/2 Server at igniter_test Port 80


Someone has an idea of what i have to fix?
#2

[eluser]Michael Wales[/eluser]
MySQL doesn't work like SQLite - where you can actually reference the database file. MySQL launches a server instance and that instance accesses the files for you. Your database config should be:

Code:
$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "igniter_test";

Unless your friend got you to somehow overwrite that localhost points to 127.0.0.1 - if that's the case A) don't trust your friend anymore; B) you could use the IP or just add localhost back to your host file.

It sounds like your friend's idea of being more professional has really messed your day up. Never change a process you are used to - everyone has their own development environment. Mine is probably vastly different, and I know it would be considered unprofessional by your friend - but a glance at my invoices in Freshbooks tells me I am perfectly professional. Smile
#3

[eluser]blackdog[/eluser]
Edit: thanks for the reply, well, i still trust him, i don't trust myself, i don't have surely enough knowledge in setting up a server and so on, actually, i recognise i'm quite ignorant in the matter :red:

btw,
Ok ALMOST resolved the problem.

I made a test connecting to the DB by hand-scripting (using some stuff i've done). And the connection was successful.
Just after i noticed a difference:

Code:
$db_connection = mysql_connect("localhost", "root", "root") or die("Connessione al database non riuscita!");

i'm used to work on the PC with EasyPHP, and they don't set a pwd in the mysql db, while mamp does :red:

SO THE CONNECTION WORKS and the scaffolding shows me the record i've inserted by hand via phpmyadmin... BUT when i try to use it to ADD A NEW RECORD i still get the "Not Found" error :down: i know that it's not the focus of the CI tutorials using the scaffolding, but i'd like to understand why it doesn't work, to acquire some knowledge Wink
#4

[eluser]blackdog[/eluser]
"EDIT"

Ok, i fixed also the scaffolding.
I noticed that when giving the "Not Found" error, the url was strange, it was searching for an "/spublic/index.php", now in the config.php i corrected and have:

$config['base_url'] = "http://igniter_test/";
$config['index_page'] = "/index.php";

and the scaffolding works!




Theme © iAndrew 2016 - Forum software by © MyBB