Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Error in mySQL from PHP

  • 11-03-2005 11:20am
    #1
    Registered Users, Registered Users 2 Posts: 721 ✭✭✭


    I am trying to load information from an SQL file into my database via PHP, but i get a strange error when i try to access the sql script (sql.php), please note this script works fine when loaded into mysql outside of PHP.

    I receive this error:

    "You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'Array' at line 1"

    This is the code im using to access it

    function getSqlQueries($file)
    {
    $file = file($file); // Weird line, huh? But it works!
    $file = explode(";", $file);
    return $file;
    }

    mysql_connect($_POST, $_POST, $_POST) or die (mysql_error());

    foreach(getSqlQueries('admin/sql.php') as $col => $val)
    mysql_query($val) or die(mysql_error());

    mysql_close();

    SQL.PHP looks like this:

    DROP DATABASE core;
    CREATE DATABASE core;
    USE core;

    CREATE TABLE core_article
    (
    article_id INT NOT NULL AUTO_INCREMENT,
    title VARCHAR(120) NOT NULL,
    subtitle VARCHAR(250) NOT NULL,
    author_id INT NOT NULL,
    cat_id INT NOT NULL,
    body TEXT NOT NULL,
    enabled SMALLINT NOT NULL,
    timestamp INT NOT NULL,
    PRIMARY KEY (article_id),
    FOREIGN KEY (author_id) REFERENCES core_users(user_ID),
    FOREIGN KEY (cat_id) REFERENCES core_article_category(article_categoryID)
    )TYPE=MyISAM;

    CREATE TABLE core_article_category
    (
    article_categoryID INT NOT NULL AUTO_INCREMENT,
    category_name VARCHAR(200),
    PRIMARY KEY (article_categoryID)
    )TYPE=MyISAM;

    CREATE TABLE core_users
    (
    user_ID INT NOT NULL AUTO_INCREMENT,
    user_name VARCHAR(200) NOT NULL,
    user_password VARCHAR(20) NOT NULL,
    user_email VARCHAR(100) NOT NULL,
    user_join INT,
    user_class INT,
    PRIMARY KEY (user_ID),
    FOREIGN KEY (user_class) REFERENCES core_user_classes(class_id)
    )TYPE=MyISAM;

    CREATE TABLE core_user_classes
    (
    class_id INT NOT NULL AUTO_INCREMENT,
    class_name VARCHAR(200) NOT NULL,
    PRIMARY KEY (class_id)
    )TYPE=MyISAM;

    CREATE TABLE core_comments
    (
    comment_id INT NOT NULL AUTO_INCREMENT,
    comment_pid INT NOT NULL,
    comment_subject VARCHAR(200) NOT NULL,
    comment_body TEXT NOT NULL,
    comment_author VARCHAR(200) NOT NULL,
    comment_author_email VARCHAR(200) NOT NULL,
    comment_disabled TINYINT(3) NOT NULL,
    PRIMARY KEY (comment_id),
    FOREIGN KEY (comment_pid) REFERENCES core_article(article_id)
    )TYPE=MyISAM;

    CREATE TABLE core_upload
    (
    upload_id INT NOT NULL AUTO_INCREMENT,
    upload_name VARCHAR(200) NOT NULL,
    upload_category INT NOT NULL,
    upload_description TEXT NOT NULL,
    upload_datestamp INT,
    PRIMARY KEY (upload_id),
    FOREIGN KEY (upload_category) REFERENCES core_upload_cat(upload_catid)
    )TYPE=MyISAM;

    CREATE TABLE core_upload_cat
    (
    uploadcat_id INT NOT NULL AUTO_INCREMENT,
    uploadcat_name VARCHAR(200) NOT NULL,
    PRIMARY KEY (uploadcat_id)
    )TYPE=MyISAM;

    CREATE TABLE core_forum_topics
    (
    topic_id INT NOT NULL AUTO_INCREMENT,
    topic_title VARCHAR(150) NOT NULL,
    topic_timestamp datetime,
    topic_author INT,
    PRIMARY KEY (topic_id),
    FOREIGN KEY (topic_author) REFERENCES core_users(user_ID)
    )TYPE=MyISAM;

    CREATE TABLE core_forum_posts
    (
    post_id INT NOT NULL AUTO_INCREMENT,
    post_tid INT NOT NULL,
    post_body TEXT,
    post_timestamp datetime,
    post_author INT,
    PRIMARY KEY (post_id),
    FOREIGN KEY (post_author) REFERENCES core_users(user_ID),
    FOREIGN KEY (post_tid) REFERENCES core_forum_topics(topic_id)
    )TYPE=MyISAM;

    anyone have any ideas?


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    I havent got a full solution but the problem seems to be this

    $file = explode(";", $file);


    Because if I comment out everything else in your script and place
    echo $file[0];
    

    nothing is returned, but if I take out the explode part, I do get a returned value

    If the array is correct, I should get some kind of returned value


Advertisement