SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2008
    Posts
    455
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question PHP/MySQL execute prepared statements stored in files

    Hi,

    I have a .sql file which contains the following;
    • Setting variable
    • Prepared statements generation
    • Prepared statement execution


    I've tried using file_get_contents() and mysql load data infile (I may be using it for the wrong task).

    How would I execute this file?

    Cheers,
    Michael

  2. #2
    Foozle Reducer ServerStorm's Avatar
    Join Date
    Feb 2005
    Location
    Burlington, Canada
    Posts
    2,699
    Mentioned
    89 Post(s)
    Tagged
    6 Thread(s)
    Hi Michael,

    Normally SQL is not read from file like you have setup. If sql does come from a file it is commonly just the statements to execute but not the connector prepared statements or execution.

    If you need to read from a file you would typically do something like:
    1. read sql statements from file into a variable, say $sql;
    2. next, use this in your php page.
    PHP Code:
       $sql file_get_contents(select_companies.sql);
       
    $stmt $o_Db->prepare($sql);
       
    $result $stmt->execute(); 
    Your select_companies.sql might look like:
    Code:
    SELECT
      comany_id
      , company_name
    FROM
     companies
    This is a bit of a shot in the dark as you did not show any of your files that you read from or the code that you are using.

    Regards,
    Steve
    ictus==""


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •