4

How can I test for active MySQL connections? I am trying to move one site to windows platform, and MySQL connections are failing; db_query() returns FALSE.
I am not sure how to use drupal_test_mysqli().

  • $flag = db_is_active(); tried this it returns true , but any db_query return s false , am sure query is correct in syntax – GoodSp33d Mar 30 '11 at 9:43
  • 1
    Did you open the logs? MySQL, Apache and PHP have almost certain explained quite detailed what your problem is, in the server logs. Use the Logs, Luke – berkes Mar 30 '11 at 10:02
  • have checked logs theres no error ,although in php.ini if set display_errors as on i get mysql server gone away while inserting into watchdog . i checked db_version() db_is_active() all returns true values, its not inserting or fetching records from db – GoodSp33d Mar 30 '11 at 10:28
  • i tried drupal_schema_fields_sql($table="zipcode",$prefix=NULL); i wont get any value for this . . . – GoodSp33d Mar 30 '11 at 10:29
  • @kantu: Does MySQL-log itself not show the errors? "MySQL has gone away" often indicates a crash of MySQL, which will be reported in the MySQL logs, often with details on why it crashes, or at least a code that allows you to google for an answer, or that you can paste here. – berkes Mar 30 '11 at 12:17
3

The function is invoked with code similar to:

$success = array();
$url = 'mysqli://username:password@localhost/databasename';

require_once './includes/install.mysqli.inc';
$err = drupal_test_mysqli($url, $success);

Replace username, password, localhost, and databasename with the values correct for your site.
The variable $success will contain an array with a value for each SQL instruction that has been executed with success.

  • i get call to undefined function drupal_test_mysqli() – GoodSp33d Mar 31 '11 at 4:52
  • I updated the answer: the function is defined in a file that is not automatically loaded by Drupal; it is used by Drupal only when it is being installed. – kiamlaluno Mar 31 '11 at 5:19
  • Isn't this a D6 function? – ram4nd Mar 6 '14 at 13:51
  • @ram4nd Yes, it is. It is the question that is using the wrong tags, since the OP is expressly asking how to use drupal_test_mysqli(). – kiamlaluno Mar 6 '14 at 15:41
  • @kiamlaluno I just said it because of the wrong tag that seems to be fixed now. – ram4nd Mar 6 '14 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.