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

MySQL and files...

Options
  • 03-08-2006 5:12am
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    Does anyone know of any way to read a file using an SQL query?

    There... short and simple :p


Comments

  • Closed Accounts Posts: 6,151 ✭✭✭Thomas_S_Hunterson


    SQL is for databases, and AFAIK, it can't be used to read "files", unless you import the files into the database as a table, which would probably defeat the point.

    What sort of file is it?


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Well for example, if I wanted to read a value into an entry in a table from a file, could it be done through SQL? I know MS-SQL let's you execute commands and all sorts of ****e but can't find the same about MYSQL


  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    grasshopa wrote:
    Well for example, if I wanted to read a value into an entry in a table from a file, could it be done through SQL?
    MS-SQL might allow it because it knows that there is a cmd.exe or command.com shell that can invoke this but MySQL, being cross-platform, wouldn't know how to execute the commands. Or something like that.

    Could you write a script to extract the value from the file and the script would then run the SQL query (using mysql command line interface)?


  • Registered Users Posts: 304 ✭✭PhantomBeaker


    Well, you can populate a database or table or whatever by putting a lot of SQL queries into a file and then invoking

    "mysql < sqlfile" (and put in whatever user/auth command-line options you need to)

    That'll execute all the SQL commands in that file.

    Is that what you need?

    Aoife


  • Closed Accounts Posts: 1,444 ✭✭✭Cantab.


    Yes, MySQL supports databases of files. Just look at the documentation.

    You need to make sure that the MySQL server is configured so as to allow file handling.

    If file handling is not available, you could just have a database of paths+filenames stored as text elements. Store all the files in a directory and access them via the path+filename stored as a text element in your MySQL database.

    I think it's quicker to do it this way than have a database of files, but I might be wrong?


  • Advertisement
  • Registered Users Posts: 6,414 ✭✭✭kdouglas


    if it's a comma-seperated list of values, you could also possible use LOAD DATA INFILE


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Thanks, ended up using the LOAD_FILE() function in the end.


Advertisement