Is there an alternative to the PHP mysql_connect command?

Asked

Viewed 465 times

2

Everything was working fine until apparently the Nginx installation said my command mysql_connect had the following problem:

Warning: mysql_connect() [Function.mysql-connect]: Headers and client library minor version Mismatch. Headers:50173 Library:50536 in /home/such

  • 2

    First, the problem is not in the "command" but in the installation of different versions of ebiblioteca in the system. I think the natural way is to use mysqli_, which is made for Mysql. Now, if using other DB architectures, PDO is an alternative to consider, as answered. If you don’t want to use another base, mysqli_ makes more sense.

2 answers

4


Yes, the PDO.

<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
?>

http://php.net/manual/en/book.pdo.php

But this error happens when php version and mysql libraries are different.

Either you update PHP and recompile it or mysql.

You can try installing/updating php5-mysqlnd.

Just for the record, this is a Warning. Your application will not fail to work.

PHP is warning that the native php and dp mysql libraries are in different versions.

Important note is that mysql_connect is deprecated. Today, by PHP guidance, one should use either the PDO or the mysqli_connect

  • 2

    Your answer is somewhat correct, more and if it is an application already in use, with hundreds or thousands of files? Rewrite all?

  • 1

    I’ll improve the answer. XD

3

I also recommend using PDO, because your DAL layer is not dependent on which database version to use, now one day you can migrate your application to POSTGRE, MSSQL...

Anyway, another alternative is to use Mysqli_connect():

$link = mysqli_connect("host","usuario","senha","db");

Source:

http://br1.php.net/manual/en/function.mysqli-connect.php

  • 3

    Yes, even mysql_connect is deprecated.

  • but even so many people insist on using, it is very common to see questions with systems with sqli failure, still post the link of the site... unfortunate

Browser other questions tagged

You are not signed in. Login or sign up in order to post.