After being side-tracked and delayed by a frustrating character encoding problem Can't Match Some (Foreign) Films After Table Convert to UTF8 (General or Unicode) - #19 by Mittineague I decided to put my arrays into a database.
For fun I used mysqli_ procedural, mysqli_ OOP, and PDO
Despite my being a relative newbie at Normalization, for example purposes I’ll digress and post them.
First up, mysqli_ procedural
$db_connection = mysqli_connect(HOST, USERNAME, PASSWORD, DATABASE);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$create_countries_table_query = "CREATE TABLE IF NOT EXISTS `" . $countries_table_name
. "` (
`id` TINYINT UNSIGNED NOT NULL
, `name` VARCHAR(100) NOT NULL
, PRIMARY KEY (`id`)
);";
$create_countries_table_result = mysqli_query($db_connection, $create_countries_table_query);
if (!$create_countries_table_result) {
echo "create_countries_table_result FAIL " . mysqli_error($db_connection) . "<br/><br/>";
}
$create_states_table_query = "CREATE TABLE IF NOT EXISTS `" . $states_table_name
. "` (
`name` VARCHAR(100) NOT NULL
, `country_id` TINYINT UNSIGNED NOT NULL
, `phoneme` VARCHAR(100) NOT NULL
, PRIMARY KEY (`name`)
);";
$create_states_table_result = mysqli_query($db_connection, $create_states_table_query);
if (!$create_states_table_result) {
echo "create_states_table_result FAIL " . mysqli_error($db_connection) . "<br/><br/>";
}
$create_cities_table_query = "CREATE TABLE IF NOT EXISTS `" . $cities_table_name
. "` (
`name` VARCHAR(100) NOT NULL
, `state_name` VARCHAR(100) NOT NULL
, `phoneme` VARCHAR(100) NOT NULL
, PRIMARY KEY (`name`, `state_name`)
);";
$create_cities_table_result = mysqli_query($db_connection, $create_cities_table_query);
if (!$create_cities_table_result) {
echo "create_cities_table_result FAIL " . mysqli_error($db_connection) . "<br/><br/>";
}
mysqli_close($db_connection);
Of course these are simple CREATE TABLE queries, but notice that
mysqli_connect()
differs from mysql_connect()
in that it takes the database name as a parameter and does not need an equivalent mysql_select_db()
function to create the resource.
mysqli_query()
differs from mysql_query()
in that the resource and query parameters are reversed
I may need to run some ALTER TABLE queries at some point, but this has been good enough for a start for my purposes.