0

so I installed WAMP and a mysql database (not using the one that comes with wamp). I can connect from MySql Workbench to the server but not from the php page. They are both on the same machine and the script looks like this:

<?php

/**
 * A class file to connect to database
 */
class DB_CONNECT
{

    // constructor
    function __construct()
    {
        // connecting to database
        $this->connect();
    }

    // destructor
    function __destruct()
    {
        // closing db connection
        $this->close();
    }

    /**
     * Function to connect with database
     */
    function connect()
    {
        // Connecting to mysql database
        $con = mysql_connect("127.0.0.1:3306", "userMan", "passDoor") or die(mysql_error());

        // Selecing database
        $db = mysql_select_db("testdb") or die(mysql_error());

        // returing connection cursor
        return $con;
    }

    /**
     * Function to close db connection
     */
    function close()
    {
        // closing db connection
        mysql_close();
    }
}

?>

This row:

$con = mysql_connect("127.0.0.1:3306", "userMan", "passDoor") or die(mysql_error());

Tells me:

Fatal error: Call to undefined function mysql_connect() in C:\wamp\www\website\db_connect.php on line 32

It worked before but now "suddenly" it stopped working, any thoughts?

UPDATE:

I tried to use mysqli instead since mysql_* is deprecated and so I did this:

I find hte php.ini being used from phpinfo() and make sure these are uncommented:

extension=php_mysql.dll
extension=php_mysqli.dll

I also tried this with commenting php_mysql.dll,

I add this to my php script to see if it works:

if (!function_exists('mysqli_init') && !extension_loaded('mysqli'))
        {
            echo 'We don\'t have mysqli!!!';
        }
        else
        {
            echo 'Phew we have it!';
        }

and my result is "We don't have mysqli!!!".

I am running wamp on windows 8.1, php is version 5.4.12 and I have also checked that the extension_dir in php.ini is correct.

What may I be doing wrong?

3
  • 2
    Please stop using mysql_* functions. They've been deprecated. Commented Mar 30, 2014 at 15:13
  • I made an update about problems with trying to use mysqli instead. Commented Mar 30, 2014 at 17:01
  • 1
    I solved this by uninstalling wamp and installing apache + php manually. Commented Mar 30, 2014 at 19:59

1 Answer 1

2

Your mysql driver is not loaded. Uncomment extension=php_mysql.dll in php.ini. Also I suggest you to use mysqli or PDO. You are using deprecated one.

In order to find php.ini location, you can use php --ini in commandline

Sign up to request clarification or add additional context in comments.

2 Comments

ok so I ent in to php.ini and did this: extension=php_mysql.dll and extension=php_mysqli.dll and then I check if I have mysqli extension like this: if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) and it tells me that I don't have it. I also did a reboot after. I made sure the dll file exists in the extension_dir = "c:/wamp/bin/php/php5.4.12/ext/"
If it exists remove comment at the end. Of not, add it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.