Vishnu
Vishnu

Reputation: 2452

Debug sql Query If failed

I have query like below

function getConnected($host,$user,$pass,$db) {

   $mysqli = new mysqli($host, $user, $pass, $db);

   if($mysqli->connect_error) 
     die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());

   return $mysqli;
}

$sqli= getConnected('localhost','db','pass','user');



    if ($data = $sqli->query("INSERT INTO `buy_diet`.`rcat` (`cat`, `id`) VALUES ('$cat', '$idea');")) {
     echo $data;
    }
    else
    {
    echo "fail";
    }

above code always failing..database is connected and all other queries like select , update etc are working fine , But INSERT query is failing...I have tried to copy the exact statement and run the query in phpmyadmin ,its working but not in above php code.

So how can I debug whats the problem.Right now I get only this error (bool)false , How to see detailed error.

Upvotes: 1

Views: 3371

Answers (2)

Kiren S
Kiren S

Reputation: 3097

Just look at the mysql error log file to get the exact problem. To get the log file use this link How to see log files in MySQL?

Upvotes: 0

Niels Keurentjes
Niels Keurentjes

Reputation: 41958

Replace echo "fail" with echo $sqli->error to see the actual problem.

Upvotes: 1

Related Questions