Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP 5.4 development server doesn't recognize mysql_connect()

Tags:

php

mysql

I am trying to use the new development server in PHP 5.4. It runs phpinfo() just fine but on my site code and also phpMyAdmin.php they are throwing the following error:

Call to undefined function mysql_connect()

They are running through localhost:8000

php -m is showing that mysqlnd is loaded but that maybe not enough.

The OS is Windows 7

Any thoughts?

like image 363
Bob Brunius Avatar asked Feb 11 '12 21:02

Bob Brunius


2 Answers

mysqlnd is the library that can be used since PHP 5.3, instead of libmysql, by 3 PHP extensions :

  • mysql, which provides the mysql_* functions,
  • mysqli, which provides the mysqli_* functons,
  • and pdo_mysql, which allows one to use PDO with a MySQL database.

mysqlnd by itself doesn't export any function you can use from your PHP scripts : it only provides MySQL connectivity to those 3 extensions -- which are the ones that export functions you can use.


If you want to use the mysql_* functions, you have to make sure that the mysql extension is enabled, with something that whould look like this in one of the .ini files parsed by PHP :

extension=mysql.dll


As a sidenote : the mysql_* functions should not be used anymore, especially for new projects : the mysql extension is old, and doesn't allow one to use recent (well, not that recent anymore, actually) features of MySQL.

Instead, you should be using mysqli or PDO.

like image 133
Pascal MARTIN Avatar answered Sep 18 '22 05:09

Pascal MARTIN


It's because register_globals is no longer included as of PHP5.4, in earlier versions it was deprecated and you could force it on. The reason is because it would leave huge security gaps for hackers to exploit.

like image 33
Craig Avatar answered Sep 20 '22 05:09

Craig