Hey guys, here is the piece of code that I am using that is located w/in a folder… I type http://localhost/additem and the 3rd “IF” statement is thrown, I am tried moving a copy of the DB Folder itself to the same master folder that the additem folder is located w/in…
<?php
$link = mysqli_connect(‘localhost’, ‘root’, ‘’);
if (!$link)
{
$output = ‘Unable to connect to the database server.’;
include ‘output.html.php’;
exit();
}
if (!mysqli_set_charset($link, ‘utf8’))
{
$output = ‘Unable to set database connection encoding.’;
include ‘output.html.php’;
exit();
}
if (!mysqli_select_db($link, ‘ijdb’))
{
$output = ‘Unable to locate the joke database.’;
include ‘output.html.php’;
exit();
}
$sql = ‘CREATE TABLE joke (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
joketext TEXT,
jokedate DATE NOT NULL
) DEFAULT CHARACTER SET utf8’;
if (!mysqli_query($link, $sql))
{
$output = 'Error creating joke table: ’ . mysqli_error($link);
include ‘output.html.php’;
exit();
}
$output = ‘Joke table successfully created.’;
include ‘output.html.php’;
?>
Well I tried that already and it didnt work… and according my “Site Point” book. it says mysqli_query(link, query) which means you pass the link before you pass the item you want. BUT, either way, I am still getting the same error message. Also, I tried switching the link, utf8 and when i do… it throws the 2nd error
Is this the way it should look? B/C if so, I am not seeing a error msg. btw, I tried mysqli_select_db($link, ‘ijdb’) or die(mysqli_error()); and I still do not get any sort of error msg.
if (!mysqli_select_db($link, ‘ijdb’));
{
$output = die(mysqli_error());
include ‘output.html.php’;
exit();
}
I must admit, this one is throwing me for a loop. I’ve never not gotten an error message from a failed database connection, so I’m a bit at a loss. The only other thing I can think of is that the user is not permitted to access the table, but if you are using the root account, that shouldn’t be an issue and it should still throw an error message.
Actually I have never done this before… I only have 2 tables in my DB… one is icdb and the other is ijdb. I have tried to change the text for the other db and it still wont connect. BTW, this is all stored locally on my computer…
Do you have the same user/password combo in your scripts as you use for myphpadmin? You said you can get to the table via myphpadmin, so if the user/pass is different for that interface, try switching it.
From what I can tell, my user/passwords are root/root, although I am not sure all the places to check for that. I do know that
mysqladmin is set for root/root,
/Applications/MAMP/bin/phpMyAdmin is also set for root/root,
and
/Applications/MAMP/bin/mamp/index.php is set to root/root