#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    58
    Rep Power
    9

    Simple SQLite3/php query


    Any ideas why I'm getting ->

    [Sun Sep 08 20:33:42 2013] [error] [client 127.0.0.1] PHP Parse error: syntax error, unexpected '=' in /var/www/ET/process2.php on line 17, in /var/log/apache2.error.log when I run the following code?


    PHP Code:
    <?php

    echo "<html>";
    echo 
    "<head>";
    echo 
    "</head>";
    echo 
    "<body>";

    $db = new SQLite3('./et.sqlite3'SQLITE3_OPEN_READWRITE);

    if(!
    $db)
    {
            echo 
    "Could not open/access DB";
    }
    else
    {
            echo 
    "Database is here";
            
    name $db->query("select fname FROM customers WHERE fname = Garrett");
            echo 
    $name;
    }

    echo 
    "</body>";
    echo 
    "</html>";
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    875
    Rep Power
    275
    you forgot the $ in front of name on your query line.
    should be
    PHP Code:
            echo "Database is here";
            
    $name $db->query("select fname FROM customers WHERE fname = Garrett");
            echo 
    $name
    but, I don't believe you will be able to "echo" that query result as I believe $name will end up being an object, not a string...so, you will have use fetch and then echo whatever you "fetch".
    Last edited by DonR; September 9th, 2013 at 10:23 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Dec 2004
    Posts
    3,008
    Rep Power
    376
    actually it will be a resource id or something like that.

    you better learn pdo or mysqli if you have just started php
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2006
    Posts
    58
    Rep Power
    9

    How about now


    How about now? I had it displaying the first name before I created the while loop but now I can't get it to display anything other than "Database is here". What I wan't it to od is display each column side by side, so it would pretty much bu the row seperated by spaces. Below is were I'm at now.

    PHP Code:
    <?php

    echo "<html>";
    echo 
    "<head>";
    echo 
    "</head>";
    echo 
    "<body>";

    $db = new SQLite3('./et.sqlite3'SQLITE3_OPEN_READWRITE);

    if(!
    $db)
    {
            echo 
    "Could not open/access DB";
    }
    else
    {
            echo 
    "Database is here\n";
            
    $row $db->query("select fname FROM customers");
            
    //$display = $name->fetchArray(SQLITE3_NUM);
            //echo $display[0];

            
    $i 0;

            while(
    $display $row->fetchArray(SQLITE3_NUM));
            {
                    echo 
    $display[i]." ";
                    
    $i++;
            }
    }

    echo 
    "</body>";
    echo 
    "</html>";
    ?>

    Originally Posted by DonR
    you forgot the $ in front of name on your query line.
    should be
    PHP Code:
            echo "Database is here";
            
    $name $db->query("select fname FROM customers WHERE fname = Garrett");
            echo 
    $name
    but, I don't believe you will be able to "echo" that query result as I believe $name will end up being an object, not a string...so, you will have use fetch and then echo whatever you "fetch".
  8. #5
  9. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6352
    You continually forget the dollar signs and that's not the proper way to loop through a sqlite result set. In fact, fetchArray() isn't even a valid method for sqlite result sets, it's just called fetch(). The Manual has more.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo