Help! Fatal error: Call to undefined function mysql_connect()

Discussion in 'PHP' started by applening56, Dec 10, 2008.

  1. #1
    Fatal error: Call to undefined function mysql_connect()

    above is the error i got when i tried to run this code:

    <?php
    mysql_connect("localhost", "root", "root") or die(mysql_error());
    echo mysql_error();
    echo "Connected to MySQL<br />";
    mysql_select_db("test") or die(mysql_error());
    echo "Connected to Database";
    ?>

    i'm new to php and just installed php 5.2.8 and apache 2.2 on vista home premium (i had MySQL5.0 installed before)

    it seems php cannot talk to MySQL. i don't see any information about MySQL when i run phpinfo()

    i copied php_mysql.dll to c:\program files\php\ext and set the extension_dir as the same in php.ini. i also have php_mysql.dll and libmysql.dll in system32 folder.

    i've been playing around with php.ini for a while and i'm running out of options now. does anybody have an idea what the problem might be?? help!

    thanks in advance!
     
    applening56, Dec 10, 2008 IP
  2. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Seems MySQL is not installed? Try using Xampp at ApacheFriends.org, it's great, or Wamp ( I've had problems with Wamp ). Both are free and will run on Vista ( I don't know if Wampp will, but Xampp does ).

    If you use either of the two, check that the MySQL service is running. In Xampp, you have to open the control panel and hit start. Probably about the same in Wamp, right click the task bar icon for Wamp and start the mysql service.
     
    xxKillswitch, Dec 10, 2008 IP
  3. applening56

    applening56 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for your reply!

    MySQL is up and running. i can connect to it using the GUI tools.

    i really don't know what else i could do...
     
    applening56, Dec 10, 2008 IP
  4. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #4
    rohan_shenoy, Dec 10, 2008 IP
  5. applening56

    applening56 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks, but i did all that and it still doesn't work.

    i plan to uninstall php 5 and install php 4 instead...
     
    applening56, Dec 10, 2008 IP
  6. kailash

    kailash Well-Known Member

    Messages:
    1,248
    Likes Received:
    42
    Best Answers:
    0
    Trophy Points:
    190
    #6
    Probably this article will help you. Or you can use Xampp as mentioned by xxKillswitch. It is easy to use.

    Kailash
     
    kailash, Dec 10, 2008 IP
  7. applening56

    applening56 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    I've given up on php5 and installed php4. it's working fine with MySQL now.

    Thanks for looking into it!
     
    applening56, Dec 11, 2008 IP
  8. SornSoft

    SornSoft Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    php5 has alot more features that could be useful in the future. I would try getting it to work propely

    Here is a sample file I include on each page I need DB work on.

    dbConnect.php
    
    <?
    	//Please Change the values below to reflect your servers settings!
    	$dbUser = "admin";
    	$dbPass = "myPass";
    	$dbName = "myDBName";
    	
    	// Handles DB Connection DO NOT CHANGE CODE BELOW THIS LINE!!!
    	$con = mysql_connect("localhost", $dbUser, $dbPass) or die(mysql_error());
    	mysql_select_db($dbName,$con) or die(mysql_error());
    ?>
    
    Code (markup):
    Then on each page that needs DB work done on them instead of rewriting this over and over you can simply use this line at the top of each page to include and connect to the db.

    
    
    <?
       include_once("dbConnect.php");
    
       // My page code doing what ever db work I need done.
    
       mysql_close($con);	// This is important it closes the db connection after the work is completed free the resource on your server.
    ?>
    Code (markup):
     
    SornSoft, Dec 11, 2008 IP