Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry Reading Mysql Files with PHP

    Hello Everyone,

    Okay I am trying to read a .sql file in php and run it into a query.

    The .sql file is perfectly fine becuase I can put it into phpmyadmin and it works great. But when I pull it from the file it errors everytime. I just dont get it.


    here is the code I am using:
    PHP Code:
    //Insert defualt data into tables
    if(!$f1=fopen("mysql_schema.sql","r")){
    error("Sorry but we could not open the mysql schema Insert file. Please make sure you have uploaded the file in the correct folder.");
    }
    $r1=fread($f1,10000);
    $create_tables=@mysql_query($r1);
    if(!
    $create_tables){
    error("Sorry but we had a problem creating the tables. Please make sure you have correct mysql information. Your host will provide you with this information." mysql_error());


    ANY help is very appreciated!!!
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog

  • #2
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Print and echo are your friends. Print the SQL to screen and check it for errors.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You may well find that phpMyAdmin processes the SQL a tad differently than a normal call to mysql_query($sql). Certainly phpMyAdmin can explode any SQL to component parts and process each in turn - eg

    TRUNCATE TABLE `first_table`;
    TRUNCATE TABLE `second_table`;

    works fine in phpMyAdmin though would not work within a call to mysql_query due to having two commands rather than one.

    See if you can grab areas of the schema.sql and process each in turn - maybe just explode by ; (dunno whether that is good for inserts though)

    Also check the comments are actual comments and that you have no hashs missing.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    FL, USA
    Posts
    734
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay I will try to see if I can't explode it in some way. Thanks okkie.
    CYWebmaster.com - See why we dot com!!
    ACJavascripts.com - Cut & Paste Javascripts!
    SimplyProgram.com - Personal Blog


  •  

    Posting Permissions

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