1

I'm following php/mysql tutorial book. The sample script connects me to my mysql database doesn't show what it should.

The line in question is

("Host information: %\n", mysqli_get_host_info($mysqli));

There rest of the code

 <?php
$mysqli=new mysqli("localhost", "root", "Im not pasting this", "or this");

if (mysqli_connect_errno()){
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
    } else {
        printf("Host information: %\n", mysqli_get_host_info());
}
?>

I just i get "Hostname: " on the screen.

1 Answer 1

2

You need to specify your mysqli object in mysqli_get_host_info() function - http://php.net/manual/en/mysqli.get-host-info.php. Try this code:

     <?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* print host information */
printf("Host info: %s\n", $mysqli->host_info);

/* close connection */
$mysqli->close();
?>
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.