-1

I'm trying to echo data from DB but it is showing 500 error. Same code works in some other server but it is not working in my present diff server.

  <?php 
    error_reporting(0); 
    session_start(); 
    $hostname_dbConn = "localhost";
    $database_dbConn = "data_data"; 
    $username_dbConn = "user_data"; 
    $password_dbConn = "datauser"; 
    $dbConn = mysql_pconnect($hostname_dbConn, $username_dbConn, $password_dbConn) or trigger_error(mysql_error(),E_USER_ERROR); mysql_select_db($database_dbConn, $dbConn);  
    $query_getconfig = "SELECT * FROM configuration WHERE status = 'A'"; 
    $getconfig = mysql_query($query_getconfig, $dbConn) or die(mysql_error()); 
    $row_getconfig = mysql_fetch_assoc($getconfig); $totalRows_getconfig = mysql_num_rows($getconfig); 
?>
nikhil gantyala
  • 311
  • 1
  • 2
  • 6
  • Please add more information about your problem: what is the SQL query you use to echo your data, what is your echoing script, add the error message that accompanies your 500 error if that is also printed. And if possible, explain to us what you think is different on this server (the one with the error) from the server on which your script is working. – Sander Vanden Hautte Aug 04 '19 at 07:01
  • please check above code. It is working in one server but not working in the diff server. – nikhil gantyala Aug 04 '19 at 07:02
  • You should check out https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php as using `mysql_` is not recommended. – Nigel Ren Aug 04 '19 at 07:15

1 Answers1

0

Remove error_reporting(0); and check what errors exactly are you facing?

Either @mysql_pconnect($hostname_explorecalirfornia, $username_explorecalirfornia, $password_explorecalirfornia) or trigger_error(mysql_error(),E_USER_ERROR);  //@ infront of mysql_pconnect or use below written code

    $mysqli = new mysqli(HOST, USERNAME, PASSWORD, DBNAME);
    if ($mysqli->connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
     }

For fetch record.

$sql= "SELECT * FROM configuration WHERE status = 'A'";
// get the result object.
$result = $mysqli->query($sql);
// fetch the result row.
$data = $result->fetch_assoc();

return $data;

with mysqli

$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();
  }

$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
$result=mysqli_query($con,$sql);

// Numeric array
$row=mysqli_fetch_array($result,MYSQLI_NUM);
printf ("%s (%s)\n",$row[0],$row[1]);

// Associative array
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
printf ("%s (%s)\n",$row["Lastname"],$row["Age"]);

// Free result set
mysqli_free_result($result);

mysqli_close($con);
Dilip Hirapara
  • 14,810
  • 3
  • 27
  • 49