0

I am trying to migrate an application from PHP 5.2.X to PHP 5.4.4 and I am having a few problems related to how the app connects to the database.

The new server fails on this line:

$this->db = @mysql_pconnect(_DBHOST,_DBUSER,_DBPASS);

I know that the new versions have changed the way the apps connect to the database but I have been trying to connect with other methods and I couldn't. I think it should be related to the server configuration which can be found here: http://bit.ly/S2px7Q

What I see is that mysqlnd is installed but not the mysql, mysqli or PDO. Is that correct?

7
  • 2
    Maybe removing the @ will shed some light on the cause of the problem, mmm? Commented Aug 17, 2012 at 19:30
  • 4
    It may not help answer your question, but you should stop using mysql_* functions. They're being deprecated. Instead use PDO (supported as of PHP 5.1) or mysqli (supported as of PHP 4.1). If you're not sure which one to use, read this article. Commented Aug 17, 2012 at 19:31
  • Also, line is missing a semi-colon and has one too many parentheses - but may just be copy/paste issue. Commented Aug 17, 2012 at 19:31
  • You are correct @newfurniturey but that was because I copy pasted :). Commented Aug 17, 2012 at 19:55
  • I removed the @ but nothing appears just a IIS page with some internal error. Matt thanks for the article, for now I will try if I can get PDO to work. Commented Aug 17, 2012 at 19:56

2 Answers 2

1

If you're getting Undefined Function errors, then it means that the mysql library is not installed in your copy of PHP.

This may actually be a good thing, because this particular library is considered obsolete. PHP provides at least two good alternatives which are recommended to use instead.

I recommend that you switch all your mysql_xxx() function calls for the equivalent mysqli_xxx() calls.

This will allow you to start using a better library with minimal code changes. You could also use the PDO library, but that would involve more work if you're dealing with existing code.

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

Comments

0

I agree, try PDO

$this->db = new PDO("mysql:host=localhost;dbname=mysql", "root", "password");
$this->statement = $db->query('SELECT first_name, last_name FROM users;');
$this->users = $this->statement->fetchAll(PDO::FETCH_ASSOC);

1 Comment

When I try PDO I get: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver. Do I need to get an extension installed for this? My phpinfo is here aaascreening.com/rental/info.php

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.