SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    LOAD DATA INFILE woes!

    any one able to help me to correct this at all please

    PHP Code:
    function importdue()
    {
                    
                    
    $importduetimes $dbh->prepare("LOAD DATA LOCAL INFILE '/tmp/trains.csv' INTO TABLE Trains FIELDS TERMINATED BY ',' IGNORE 1 LINES (Due,Destination,Status,Platform,Details)");
                    
    $importduetimes->execute();
                    } 
    returns

    Code:
    Fatal error: Call to a member function prepare() on a non-object in /var/www/trains/functions.php on line 64

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    $dbh is not in the scope of importdue. You need to either pass it as a argument or make it a global. The former of course is preferred.
    The only code I hate more than my own is everyone else's.

  3. #3
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just been reading this should be a global as i've done an include before the function to set it as a global

  4. #4
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just done GLOBAL $dbh now getting closer!

    thank you very much!

    PHP Code:
    function importdue()
    {
                    GLOBAL 
    $dbh;
                    
    $sql "LOAD DATA LOCAL INFILE '/tmp/trains.csv' INSERT INTO TABLE Trains FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES  (Due, Destination, Status, Platform, Details)";
                    
    $importduetimes $dbh->query($sql);
                    
    $importduetimes->execute();
                    
                    } 
    still errors out and shows
    Code:
    Fatal error: Call to a member function execute() on a non-object in /var/www/trains/functions.php on line 67

  5. #5
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,180
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    run var_dump($dbh);exit; right after global and paste the result

  6. #6
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    object(PDO)#2 (0) { } 

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,147
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    The query method returns false on failure. The reason for this is that the query is malformed/incorrect.

    http://www.php.net/manual/en/pdo.que...y-returnvalues

    Use errorCode and errorInfo methods to debug query failure.

    http://www.php.net/manual/en/pdo.errorcode.php
    http://www.php.net/manual/en/pdo.errorinfo.php

    You can also take the query out of the application and run it directly from the command line to see why it might be failing.
    The only code I hate more than my own is everyone else's.

  8. #8
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed

    PHP Code:
    GLOBAL $dbh;
                    
    $importduetimes $dbh->prepare("LOAD DATA INFILE '/tmp/trains.csv' INTO TABLE `Trains` FIELDS TERMINATED BY ',' IGNORE 1 LINES;");
                    
    $importduetimes->execute(); 

  9. #9
    Always A Novice bronze trophy
    K. Wolfe's Avatar
    Join Date
    Nov 2003
    Location
    Columbus, OH
    Posts
    2,180
    Mentioned
    65 Post(s)
    Tagged
    2 Thread(s)
    That's concerning that I and everyone else here didn't see that the first time around, lol. Good job


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
  •