SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Member Jedric's Avatar
    Join Date
    Aug 2004
    Location
    Austin, TX
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problems with MySQL Connection Code

    When I put the following code into my mysql_connect.php file I created, it is not generating any output but I am pretty sure that it is not connecting to the database properly either. Do any of you see any problems with this code? Any way to test if it was successful or not?

    PHP Code:
    <?php
    DEFINE 
    ('DB_USER''myuser'); // Database username.
    DEFINE ('DB_PASSWORD''mypassword'); // Database password.
    DEFINE ('DB_HOST''localhost'); // Database hostname.
    DEFINE ('DB_NAME''mydbname'); // Database name.

    $dbc = @mysql_connect (DB_HOSTDB_USERDB_PASSWORD) OR die ('Could not connect to MySQL: ' mysql_error());
    @
    mysql_select_db (DB_NAME) OR die('Could not select the database: ' mysql_error());
    ?>

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try removing all the error suppressors (@) to see what error messages you're getting. (Might need to turn display errors on in php.ini)

    There is nothing in the code above that should produce any output if the connection was successful. You'll need to execute a query to do that.

  3. #3
    SitePoint Member Jedric's Avatar
    Join Date
    Aug 2004
    Location
    Austin, TX
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I tried removing those and I didn't see anything. Something must be wrong with the other part of my script.
    Is anyone willing to help me go through my code to see what the problem is? I am sure it must be something simple, but I cannot figure it out for the life of me.

  4. #4
    SitePoint Member Jedric's Avatar
    Join Date
    Aug 2004
    Location
    Austin, TX
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It wasn't working because of the escape_data(); function that I added. I will have to figure out another way to escape it.

  5. #5
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is anyone willing to help me go through my code to see what the problem is?
    It wasn't working because of the escape_data(); function that I added. I will have to figure out another way to escape it.
    The problem wasn't in any of the code you posted, so there's not a lot anyone could have done for you.

  6. #6
    SitePoint Member Jedric's Avatar
    Join Date
    Aug 2004
    Location
    Austin, TX
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cranial-bore View Post
    The problem wasn't in any of the code you posted, so there's not a lot anyone could have done for you.
    Yes, I realize that. That is why I posted up that I found the reason it was messed up. Originally I thought it was the database connection code, but it was just that one function I tried to add.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •