2

So my problem/question is i'm coding a irc bot and that bot make some request to sql but some times i need to restart the mysql and script losse the connection and display. PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result

I already tried to use "connection_aborted()" but it always return 0 tested with connected script and disconnected script i'm trying to check when he dc's to auto reconnect again but that function keep returning 0

3
  • connection_aborted() has nothing to do with MySQL :) Commented Mar 2, 2014 at 11:51
  • Can u tell what can i use to detect when script disconnect from sql ? Commented Mar 2, 2014 at 11:54
  • Already find how to detect the connection if(mysql_ping($con)) { echo "Alive Connection"; }elseif(!mysql_ping($con)){ echo "Lost Connection"; //reconnecting to sql mysql_close($con); $con = mysql_connect("localhost", "root", ""); if (!$con) { die('cant connect: ' . mysql_error()); } mysql_select_db("db", $con); } Commented Mar 2, 2014 at 12:10

1 Answer 1

1

You can use this

$link=mysqli_connect('localhost','root','','dbname');
$ping=mysqli_ping($link);
if ($ping) {
    printf ("mysqli is connected");
} else {
    printf ("mysqli is NOT connected");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.