I'm attempting to use PHP to connect to an SQL database to use to store quotes from an IRC chat bot. So far the bot seems to be running, but the sql connection isn't working and I'm not exactly sure why. I've tried reading through all sorts of sites, and I modified code I found on the WC3 schools site just to be sure I wasn't missing some huge 'derp'. Nothing seems to work, and I'm feeling my brain melt.
Relevant connection data for writing to the db:
function addquote()
{
$con=mysqli_connect("localhost","BotBot","password","Quotes");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO `Quotes`.`quotes` (`ID_NUM`, `DATA`, `USER`) VALUES (NULL, \'$qd\', \'\');");
$this->pm("Quote added to database.");
mysqli_close($con);
}
Second connection for reading a random result from the db and messaging it:
function randomquote()
{
$con=mysqli_connect("localhost","BotBot","password","Quotes");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM quotes ORDER BY RAND() LIMIT 1");
$this->pm($result);
mysqli_close($con);
}
"password" in both is being replaced with the relevant password for that user account, and the account has full access to r/w the db.
I am getting the pm("Quote added to database") line returned to me through the IRC bot, and it doesn't disconnect the moment you try to use these functions (took about a week of pokes and prods to figure out what I was doing wrong!). I'm not exactly sure how a response down past that sql connection could be working if it's not connecting, not without giving me a 'die'.
PHPMyAdmin isn't showing that 'BotBot' account even attempting a connection and dying for a bad password or anything, so... kinda running out of ideas here.
If anyone can give me a hand here, I'd be grateful for it.