-4

My connection

$db = mysql_connect('localhost','root','','');
mysql_select_db('database', $db);`

Now i have changed to this

$db = mysqli_connect('localhost','root','','');
mysqli_select_db('database', $db);

but it is not working. I have changed all my mysql functions to mysqli function, just added an 'i'; mysql to mysqli. Is it not enough?

Error is:

mysqli_select_db() expects parameter 1 to be mysqli

and

mysqli_query() expects at least 2 parameters, 1 given ..

What to do?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 3
    Look at the manuals for the functions you are using. I don't think "just adding an i" will suffice. – chris85 May 02 '15 at 17:06

1 Answers1

0

Do something like this -

<?php

// 1. Create a database connection
$connection = mysqli_connect(DB_SERVER,DB_USER,DB_PASS);
if (!$connection) {
    die("Database connection failed: " . mysqli_error());
}

// 2. Select a database to use 
$db_select = mysqli_select_db($connection, DB_NAME);
if (!$db_select) {
    die("Database selection failed: " . mysqli_error());
}
?>

It is always better to learn the topic in depth before implementing it realtime, here are few important links I have mentioned for you related to mysqli -

PHP's mysqli Extension

The mysqli extension, or as it is sometimes known, the MySQL improved extension, was developed to take advantage of new features found in MySQL systems versions 4.1.3 and newer. The mysqli extension is included with PHP versions 5 and later.

http://ca2.php.net/manual/en/book.mysqli.php

http://ca3.php.net/manual/en/mysqli.overview.php

http://php.net/manual/en/mysqli.select-db.php

Thanks!

SantanuMajumdar
  • 886
  • 1
  • 5
  • 20