SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Simple connection between MySql DB and Localhost

    Hey all,

    I've tried various versions of this string but here's how i'm trying to connect to my DB as follows:


    // connect
    $link = mysql_connect("$hostname", "$username", "$password")or die("Could not connect");
    mysql_select_db("$database") or die("Could not select database");

    I'm getting this error via my localhost:

    Fatal error: Call to undefined function mysql_connect() in C:\Webserver\Apache Software Foundation\Apache2.2\htdocs\SearchEngine.php on line 43

    Thanks in advance.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hi,

    Try checking your php.ini file and make sure this line isn't commented out:
    Code:
    extension=php_mysql.dll
    It's worth mentioning that the PHP mysql extension has been depreciated and will be removed from PHP at some point, so you should really be using the mysqli (or, better still, PDO) extension - just enable extension=php_mysqli.dll in your php.ini file and you should be good to go

    Edit: Note that you'll need to restart Apache after you make changes to php.ini

  3. #3
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fretburner,

    Thanks Fret. I should have mentioned I already checked the extension=php_mysqli.dll and there is no ";" in place in front of it because I removed it during the install. Any other ideas?

  4. #4
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    You could try creating a new PHP file like this:
    PHP Code:
    <?php phpinfo(); ?>
    When you browse to the file, you'll get a screen that details all of PHP's settings, and what modules are enabled etc.
    Check to see if there's an entry for mysql or mysqli.

    Did you install Apache/PHP/MySQL individually, or you're using some kind of LAMP package like WAMP or XAMPP?

  5. #5
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I installed them individually. mysqli and mysqli are not commented out, per the php.ini file. I made mysqli active just now to be sure. Also thanks for the tip on deprecation.

  6. #6
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey, you're right. I created the file and I don't see anything about MySQL or mysqli. What should it say and how do I activate them?

  7. #7
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Near the beginning of the phpinfo output, check a setting called 'Loaded Configuration File' and make sure it corresponds to the php.ini file you've been editing. I've had situations where there were ini files in a couple of locations and I wasn't sure if I was editing the right one.

  8. #8
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup. Its pointing to it.

  9. #9
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Hmmm.. do get any errors in your Apache or PHP error logs?

  10. #10
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My Apache error log was easy to find and nope I didn't see any files error files created there. How do I check for PHP?

  11. #11
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Under the 'Core' section of the phpinfo output, there's a setting 'error_log' which shows which folder the log is in.

  12. #12
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Core says "no value" under both local and master value. Also display_errors says "on" if that means anything to you. Thanks again for continuing to work with me. Believe it or not i'm been looking for solutions for a while..

  13. #13
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    One thing I've seen suggested over on the PHP manual is to try copying php_mysqli.dll (from the php/ext folder) and libmysql.dll (from your mysql/bin folder, I think) to your windows/system32 folder, and restart apache again.

  14. #14
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The libmysql.dll folder was actually in the Webserver folder but that's ok, I found it. I moved both files you suggested to the System32 folder and restated Apache. I tried several variations of the connect string again and no luck.

  15. #15
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you think there's a problem with my syntax perhaps?? I've tried multiple variations..

  16. #16
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,446
    Mentioned
    45 Post(s)
    Tagged
    13 Thread(s)
    Quote Originally Posted by siterightpoint View Post
    Do you think there's a problem with my syntax perhaps?? I've tried multiple variations..
    No, if it was just that then you'd be getting a different error. For some reason it seems that PHP isn't loading the extensions.

    I'm afraid I don't know what else to try at this point. The only thing I could suggest is downloading a complete LAMP package for Windows - I've used WAMP and XAMMP in the past and never had any trouble with either. They should be able co-exist with your existing setup as long as you only have one set of Apache and MySQL servers running at a time (or you change the default ports).

  17. #17
    SitePoint Member
    Join Date
    Jul 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fretburner,

    thank you very much for helping me thus far. I'll keep trying for a while and if I can't figure it out i'll do what you suggested and install a WAMP. If I find a solution before then i'll post on this thread. Cheers.


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
  •