类的PHP错误对象无法转换为字符串

I am trying to create a PHP file that connects to a mysql database and inserts data into the database. I am getting these errors:

( ! ) Catchable fatal error: Object of class foo_mysqli could not be converted to string in ( ! ) Notice: Undefined variable: host in C:\wamp\www\final_kk.php on line 21

( ! ) Catchable fatal error: Object of class foo_mysqli could not be converted to string in C:\wamp\www\final_kk.php on line 21

Line 21 is the first line inside of the try. Any help would be appreciated. Thanks!

<?php

class foo_mysqli extends mysqli {
    public function __construct($host, $user, $pass, $db) {
        parent::__construct($host, $user, $pass, $db);

        if (mysqli_connect_error()) {
            die('Connect Error (' . mysqli_connect_errno() . ') '
                    . mysqli_connect_error());
        }
    }
}

$db = new foo_mysqli('localhost', 'root', '', 'users');

echo 'Success... ' . $db->host_info . "
";

try {
            $conn = new PDO("mysql:host=$host;dbname=$db;username=$user;password=$pass", $user, $pass);


            // set the PDO error mode to exception
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



            $sql = "INSERT INTO users (fname, lname,email,username,password,SSN) VALUES ('$fname', '$lname', '$email', '$uname', '$password', '$ssn')";


            // use exec() because no results are returned
            $conn->exec($sql);
            echo "New record created successfully";
            }

        catch(PDOException $e)
            {

            echo $sql . "<br>" . $e->getMessage();
            }

    $db->close();
    ?>

Okay....I made some changes based on the comments and my code now looks like this:

<?php

class foo_mysqli extends mysqli {
    public function __construct($host, $user, $pass, $db) {
        parent::__construct($host, $user, $pass, $db);

        if (mysqli_connect_error()) {
            die('Connect Error (' . mysqli_connect_errno() . ') '
                    . mysqli_connect_error());
        }
    }
}

$db = new foo_mysqli('localhost', 'root', '', 'users');

echo 'Success... ' . $db->host_info . "
";
settype($host, "string"); 
settype($user, "string");   
settype($pass, "string");    
try {
            $conn = new PDO("mysql:host=$host;dbname=$db, $user, $pass");


            // set the PDO error mode to exception
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);



            $sql = "INSERT INTO users (fname, lname,email,username,password,SSN) VALUES ('$fname', '$lname', '$email', '$uname', '$password', '$ssn')";


            // use exec() because no results are returned
            $conn->exec($sql);
            echo "New record created successfully";
            }

        catch(PDOException $e)
            {

            echo $sql . "<br>" . $e->getMessage();
            }

$db->close();
?>

This got rid of one of my errors however I still get

( ! ) Catchable fatal error: Object of class foo_mysqli could not be converted to string in C:\wamp\www\final_kk.php on line 33

please help...what am I doing wrong?

You're setting $db as an instance of a foo_mysqli() object in this line:

$db = new foo_mysqli('localhost', 'root', '', 'users');

Later in

$conn = new PDO("mysql:host=$host;dbname=$db;username=$user;password=$pass", $user, $pass);

you're using $db as a database name. It's enclosed in a double-quoted string, so PHP will attempt to interpolate it and substitute a string in the PDO connection string. Since $db is now an object, it fails.

It's not clear why you're setting up an object that extends MySQLi when you're later using a PDO object anyway.

Additionally, you haven't defined $host in the scope where you're setting up your PDO connection, so PHP reports that as undefined.

Since you know what the host and database names are you could just do this:

    $conn = new PDO("mysql:host=localhost;dbname=users;", $user, $pass);