In the other post, you wrote this:
Quote:
------------------------------
$f_name = 'Tom';
$l_name = 'Jones';
$street = "111 Way St";
$city = 'Houston';
$state = 'TX';
$zip = '77007';
$type = "address_t() ..street($street) ..city($city) ..province($state) ..postal_code($zip)";
$stmt = $db->prepare("insert into clients (client_lname, client_fname, address) values (:db_insert_placeholder_1,:db_insert_placeholder_2 ,address_t() ..street(:db_insert_placeholder_3) ..city(:db_insert_placeholder_4) ..province(db_insert_placeholder_5) ..postal_code(db_insert_placeholder_6))");
$stmt->bindParam(':db_insert_placeholder_1',$f_name);
$stmt->bindParam(':db_insert_placeholder_2',$l_name);
$stmt->bindParam(':db_insert_placeholder_3',$street);
$stmt->bindParam(':db_insert_placeholder_4',$city);
$stmt->bindParam(':db_insert_placeholder_5',$state);
$stmt->bindParam(':db_insert_placeholder_6',$zip);
$stmt->execute();
------------------------------
|
This is basically the correct approach. But it doesn't work because you don't have a ':' in front of db_insert_placeholder_5 and db_insert_placeholder_6.
Quote:
------------------------------
$f_name = 'Tom';
$l_name = 'Jones';
$street = "111 Way St";
$city = 'Houston';
$state = 'TX';
$zip = '77007';
$type = "address_t() ..street($street) ..city($city) ..province($state) ..postal_code($zip)";
$stmt = $db->prepare("insert into clients (client_lname, client_fname, address) values (:db_insert_placeholder_1,:db_insert_placeholder_2 ,:db_insert_placeholder_3)");
$stmt->bindParam(':db_insert_placeholder_1',$f_name);
$stmt->bindParam(':db_insert_placeholder_2',$l_name);
$stmt->bindParam(':db_insert_placeholder_3',$type);
$stmt->execute();
------------------------------
|
That cannot work because you try to bind the
string "address_t() ..street($street) ..city($city) ..province($state) ..postal_code($zip)" to a value of type "address_t". But a structured type is not a string.
What is often done to avoid those problems is to define a UDF shadowing the constructor. Then use this UDF in the INSERT statement:
Code:
CREATE FUNCTION address_t(street VARCHAR(100), city VARCHAR(100), state VARCHAR(100), zip VARCHAR(10))
RETURNS address_t
RETURN address_t()..street(street)..city(city)..province(state)..postal_code(zip);
INSERT INTO clients (client_lname, client_fname, address)
VALUES (:db_insert_placeholder_1, :db_insert_placeholder_2, address_t(:db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6))
Now you don't have to remember the correct syntax to invoke the setter methods on the type in the INSERT statement - just use the function, which does the right thing.