Can Not Connect To DB

Remember when I said “You have created this database, right?”… Guess what. you havent.

No I know that, that exists… if I try to type localhost/ijdb it gives me this:

Forbidden

You don’t have permission to access /ijdb/ on this server.

if I try the localhost with any other name, it returns false, also I can see it in my myphpadmin control panel… also I have a icdb table with 30 things in it… and when I switch out the ijdb for the icdb, i get the same response

Try going into myphpadmin and in the box where it says Create New Database, type in ijdb and see what happens. If your database is there, then it should fail.

Your error says that you don’t have the database.

Trying your suggestion I get this:

#1007 - Can't create database 'ijdb'; database exists
CREATE DATABASE  `ijdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

I am going to have to guess that the localhost does not know where to locate the file…

I’m wondering if there is something in your setup that isn’t allowing your script to see the same database that your myphpadmin is.

However, try this script and see what happens. If it doesn’t fail, then try your script again:


$link = mysqli_connect('localhost', 'root', '');
if (!$link) {
echo 'Unable to connect to the database server.';
exit();
}

$sql = 'CREATE DATABASE  `ijdb` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci';
$query = mysqli_query($link, $sql) or die( mysqli_error( $link ) );

I tested this and it worked on my machine.

Will not allow me past the initial error check.

You’ll have to put your password in. If it is root then the first line would be:

$link = mysqli_connect(‘localhost’, ‘root’, ‘root’);

What if I want to delete my MAMP and MySQL. I am starting to wonder if I have servers blocking each other. Otherwise I am at a loss on what to do

I’m not sure on uninstalls in Macs. I work on a Windows system.

Did that last method work at all?

Not at all…

I’m out of ideas. Perhaps someone who is more familiar with a MAMP system will think of something.

Thx for all your help though… There has to be a simple explanation why it will not do what it is supposed to do. In the meantime, I am deleted MAMP and MySQL from the computer and will try and start over. My professor seems to think that by downloading MAMP and MySQL separately, that they are causing a conflict. I don’t think he is correct, but I don’t know either say myself.

Well, MAMP should stand for Mac Apache Mysql Php.

Perhaps you did end up with two distinct databases. Phpmyadmin saw one and your scripts saw another.

ok… well i uninstalled MAMP & MySQL (via term window) and then reinstalled MAMP, as before I can get my basic .php files to work, yet I am still unable to get this fricken server thingy to work. It is getting hung up on the 1st error agian…

‘locate the file’… a Database is not a Directory. Not the same thing.

If you cant get past $link = mysqli_connect(‘localhost’, ‘root’, ‘’);, then you’ve got a deeper problem.
instead of echo ‘Unable to connect to the database server.’;, do echo mysqli_connect_error(); and tell us what comes out.

On the 1st Error… I get No such file or directory

I think… it might have been the way I was typing in the URL… at first I was typing
localhost/connect
then I changed it to
localhost:8888/connect
and it seems to be working… I do not understand that reasoning… as I can call .php files that do not access the db w/o using the :8888

‘No such file or directory’ is a socket file issue. Your installation of PHP has got an incorrect socket file location.

Why does it work now that I am telling it what port to use tho?