Jump to content

tobiksowles

New Members
  • Posts

    2
  • Joined

  • Last visited

tobiksowles's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you for the help, Mac_G. I moved the connection information to a seperate file and now have it require_once and don't close it, this will be a pretty commonly asked for database. After a few tries, I at least managed to get it to attempt a connection, so this has gotten me MUCH further than I'd gotten on my own. I'm still unable to actually connect to the db, but that seems to be something wrong with my sql setup, like the user that supposedly has privileges doesn't actually have them. I'll keep at it though.
  2. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.