Zulu Irminger
Zulu Irminger

Reputation: 442

Adding a Varying Array (VARRAY) in MySQL

I am trying to create a table within PHP code in order to open in a browser to create the table. I need a varying array within the table and have the correct code to create it in Oracle:

CREATE TYPE ReportEntries_Type AS OBJECT
(Subject VARCHAR (500));
/

CREATE OR REPLACE TYPE ReportEntries_VA AS
VARRAY (12) OF ReportEntries_Type;
/

CREATE TABLE ReportDetails
(ReportID INTEGER NOT NULL UNIQUE,
StudentID INTEGER NOT NULL UNIQUE,
ReportEntries ReportEntries_VA,
DateLastModified DATE NOT NULL,
CONSTRAINT ReportDetails_PK PRIMARY KEY (ReportID, StudentID),
CONSTRAINT RDStudentIDSD FOREIGN KEY (StudentID)
REFERENCES StudentDetails (StudentID));

However, when placed within PHP code and added to a MySQL database, an error message appears. The code I'm using is as follows:

<?php
require "connect_to_mysql.php";

$sqlCommand = "CREATE TYPE ReportEntries_Type AS OBJECT

...cont. code from above...

REFERENCES StudentDetails (StudentID))";

if (mysql_query ($sqlCommand)) {
echo "The ReportDetails table has been created successfully!";
} else {
echo "There has been an error";
}
?>

Is it even possible? Many thanks in advance :)

Upvotes: 1

Views: 1704

Answers (1)

haltabush
haltabush

Reputation: 4528

No, it's not really possible, sorry :(

In MySQL, we usually use VARCHAR or TEXT fields with coma separated values to do that. I know, it's annoying :)

Upvotes: 1

Related Questions