-4

This is my config.php

<?php mysql_connect('localhost', 'id2266180_test', 'testtest'); mysql_select_db ('id2266180_test');?>

and this is error

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /storage/ssd2/180/2266180/public_html/config.php:9 Stack trace: #0 /storage/ssd2/180/2266180/public_html/index.php(3): include() #1 {main} thrown in /storage/ssd2/180/2266180/public_html/config.php on line 9

Sailendra
  • 1,316
  • 13
  • 26

4 Answers4

2

First thing is mysql_select_db is depcated. Use this code :

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// ...some PHP code for database "my_db"...

// Change database to "test"
mysqli_select_db($con,"test");

// ...some PHP code for database "test"...

mysqli_close($con);
?> 
Kshitij Soni
  • 404
  • 3
  • 16
  • I have this warnning in `index.html` if I change it `Warning: mysqli_query() expects at least 2 parameters, 1 given in /storage/ssd2/180/2266180/public_html/index.php on line 70 Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given in /storage/ssd2/180/2266180/public_html/index.php on line 71 Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /storage/ssd2/180/2266180/public_html/index.php on line 72` – Bøy Øf Løndøn Jul 19 '17 at 10:51
  • have you passed connection object in mysqli_query() ? – Kshitij Soni Jul 19 '17 at 12:07
0

You can also try like this:

<?php mysqli_connect('localhost','id2266180_test','testtest','id2266180_test');?>
Bug Inspector
  • 186
  • 3
  • 14
0

You should check, if mysql module is loaded. Try to find out with:

<?php
    phpinfo();
?>

If it is not loaded, you have to edit the php.ini, by loading the mysql-module. But notice, that the mysql-extension is deprecated since PHP 5.5 and removed since PHP 7.0. So try to use mysqli instead, like the others already said.

trpx
  • 168
  • 7
0

Following code you can try :

<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");

// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>
Prabhu Nandan Kumar
  • 1,060
  • 11
  • 19