PHP Code jumping on wrong database.

Discussion in 'MySQL' started by X.Homer.X, Jun 3, 2008.

  1. #1
    I have come php code that allows a user to login to my forums from the main page. The code is told what to do by config.php (below)

    
    <?php
    define('IN_PHPBB', true); //Define IN_PHPBB
    $phpbb_root_path = '../phpBB3/'; //the path to where your forums are installed
    $phpEx = substr(strrchr(__FILE__, '.'), 1); //The file extension
    include($phpbb_root_path . 'common.' . $phpEx); //Include common.php from the forums directory
    
    $user->session_begin(); //begin the user's session
    $auth->acl($user->data); //Authenticate the user
    ?>
    
    PHP:
    now the file common.php, which is included in this file is telling my login script where to get the information (the script is doing more than just logging the user in) from. The problem is. that whenever another connection is opened in my page, the login script trys to connect with that also, even though in the source, it is well after the connect and close of that database. Is there any way i can make it so that it only connects to the database its supposed to?

    BTW, config is loaded at the start, because i need common.php to check if the user is an admin at the very start of the page, and the login script is at the very bottom. If there is no mysql connect in the page it works, otherwise it says cant connect (error shown below)

    
    [phpBB Debug] PHP Notice: in file /home/content/g/a/m/gamersinsanity/html/admin/includes/left.php on line 14: mysql_query(): Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)
    [phpBB Debug] PHP Notice: in file /home/content/g/a/m/gamersinsanity/html/admin/includes/left.php on line 14: mysql_query(): A link to the server could not be established
    Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)
    
    Code (markup):
    When my login box comes before my content (where mysql is being called) or if config is after the mysql it works, but i want my content first in my source so search engines see my content first and not my sidebar, and if config is last in source, i cant check for admin.

    Please help, this has been a burden for some time now.
     
    X.Homer.X, Jun 3, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    How do you execute mysql queries? The problem could be that you do not pass a link identifier for the connection you want to use. Show the code that connects to the sql and executes queries.
     
    xlcho, Jun 3, 2008 IP
  3. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    there a few different ways depending on how i want the results to de displayed or not displayed.

    heres one

    
    $con = mysql_connect("****","*****","*****");
      if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
    
      mysql_select_db("*****", $con);
    
    $result = mysql_query("SELECT * FROM articles ORDER BY article_id DESC LIMIT 3") or die(mysql_error());
    
    while($row = mysql_fetch_array($result))
      {
      echo "<div class=\"news\">";
      echo "<div class=\"news_title\">";
      echo "<h3>&raquo; ".$row['article_title']."<span>&nbsp;".$row['article_sub']."</span></h3>";
      echo "</div>";
      echo "<p>".$row['article_content']."</p>";
      echo "<br><br>";
      echo "<p><i>Posted on: ".$row['article_date'].". By: ".$row['article_author']."</i></p>";
      echo "</div>";
      }
    mysql_close($con);
    
    PHP:
    heres another

    
    $con = mysql_connect("*****","*****","*****");
      if (!$con)
        {
        die('Could not connect: ' . mysql_error());
        }
    
      mysql_select_db("*****", $con) or die(mysql_error());
    
    $sql="DELETE FROM uploads WHERE upload_id='$_GET[upload_id]'" or die(mysql_error());
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
      mysql_close($con);
    
    PHP:
     
    X.Homer.X, Jun 3, 2008 IP
  4. X.Homer.X

    X.Homer.X Peon

    Messages:
    290
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #4
    should i be doing this another way??
     
    X.Homer.X, Jun 4, 2008 IP