3

I have mysql-installer-web-community-5.6.25.0, apache_2.4.2-x86-no-ssl and php-5.4.42-Win32-VC9-x86 installed.

php is working with apache server but not with mysql. I have enabled extension=php_mysql.dll and extension=php_mysqli.dll in php.ini and restarted my pc.I have tried adding libmysql.dll and php_mysql.dll to system32.But mysql is not displayed in phpinfo().

My phpinfo() is as follows http://192.168.1.104/test.php

Also i tried with the following php code

$continued = mysql_connect("localhost","sonetonix","sonetonix");

if($continued) {
    echo("Connection is succeed");
} else {
    echo("Connection is fail");
}

when i run the code i am getting error as Call to undefined function mysql_connect().

How can i make php and mysql work.

Burak
  • 5,252
  • 3
  • 22
  • 30
link
  • 35
  • 7
  • 4
    There is **no more support** for `mysql_*` functions, they are [**officially deprecated**](https://wiki.php.net/rfc/mysql_deprecation), **no longer maintained** and will be [**removed**](http://php.net/manual/en/function.mysql-connect.php#warning) in the future. You should update your code with [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) to ensure the functionality of your project in the future. – Ben Jun 29 '15 at 10:28
  • What php version do you use? Latest version of PHP are removed mysql_ extension. so use **PDO** or **mysqli_** extension – Nahid Bin Azhar Jun 29 '15 at 10:29
  • if you don't know anything about webserver and technologies, install xamp to start your learning – donald123 Jun 29 '15 at 10:30
  • 1
    the link to phpinfo() is a local one . – Pushkar Jun 29 '15 at 11:50
  • Mark as duplicate of https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189 ? – Roland Nov 10 '17 at 17:01

1 Answers1

0

Alter the function from mysql_connect() to mysqli_connect(). You'll need to subsequently use the MySQLi function library for further SQL queries and processing.

Using MySQLi instead of MySQL functions is very similar. The main difference is that you need to return a connection object and then use that in future queries:

$db_connection = mysqli_connect("localhost","sonetonix","sonetonix");
if (empty($db_connection)){
    die('Database connection error');
}
$result = mysqli_query($db_connection, "SELECT * FROM users");

If you are running PHP 5.3 or higher this will be enabled by default. If you are not running PHP 5.3 or higher you need to updgrade, as older versions of PHP are no longer secure and have outdated functionality. From your question it would appear you are using PHP 5.4 so all this should work.

M1ke
  • 6,166
  • 4
  • 32
  • 50
  • Updated my answer; you won't need to alter php.ini if you use `mysqli_` functions so I've just left that out. – M1ke Jun 29 '15 at 10:36
  • tried but getting error as undefined function mysqli_connect() – link Jun 29 '15 at 10:39