SQLite3 / PDO - No such table though it does exist











up vote
3
down vote

favorite












I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.



This line of PHP causes the PDOException:



$query = "SELECT * FROM users";
$results = self::$app->db->query($query);


And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.



I don't really know what to do as I am new to Slim as well as SQLite.



Thank you for your help :-)










share|improve this question
























  • I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
    – Dencker
    Oct 15 '14 at 9:40












  • Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
    – Jeahel
    Oct 15 '14 at 9:41















up vote
3
down vote

favorite












I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.



This line of PHP causes the PDOException:



$query = "SELECT * FROM users";
$results = self::$app->db->query($query);


And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.



I don't really know what to do as I am new to Slim as well as SQLite.



Thank you for your help :-)










share|improve this question
























  • I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
    – Dencker
    Oct 15 '14 at 9:40












  • Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
    – Jeahel
    Oct 15 '14 at 9:41













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.



This line of PHP causes the PDOException:



$query = "SELECT * FROM users";
$results = self::$app->db->query($query);


And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.



I don't really know what to do as I am new to Slim as well as SQLite.



Thank you for your help :-)










share|improve this question















I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.



This line of PHP causes the PDOException:



$query = "SELECT * FROM users";
$results = self::$app->db->query($query);


And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.



I don't really know what to do as I am new to Slim as well as SQLite.



Thank you for your help :-)







php pdo sqlite3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 15 '14 at 17:20









Mika Tuupola

12.1k53144




12.1k53144










asked Oct 15 '14 at 9:35









Jeahel

103211




103211












  • I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
    – Dencker
    Oct 15 '14 at 9:40












  • Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
    – Jeahel
    Oct 15 '14 at 9:41


















  • I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
    – Dencker
    Oct 15 '14 at 9:40












  • Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
    – Jeahel
    Oct 15 '14 at 9:41
















I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
– Dencker
Oct 15 '14 at 9:40






I don't have an answer to your question, but I'd recommend that you try to tag this with some kind of slim framework tag as as the prerequisities for your code snippet needs to be known (and they're probably a part of the slim framework) - so you probably wanna get some answers from people who actually works with the framework : ) My best shot would be that you didn't setup your configuration files correctly though.
– Dencker
Oct 15 '14 at 9:40














Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
– Jeahel
Oct 15 '14 at 9:41




Thanks, I did. I thought that it was only related to PDO or SQLite but I am not sure, so...
– Jeahel
Oct 15 '14 at 9:41












2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted










The database that you have opened does not contain this table.



SQLite will happily open any file name; if it does not exist, it will create a new, empty database.



Check your database file name.






share|improve this answer





















  • I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
    – Jeahel
    Oct 15 '14 at 11:04










  • The evidence shows that the database path you're using is not correct.
    – CL.
    Oct 15 '14 at 12:19






  • 1




    Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
    – Jeahel
    Oct 15 '14 at 15:34








  • 2




    A relative path is based on the current directory, which in PHP, is random.
    – CL.
    Oct 15 '14 at 17:44


















up vote
0
down vote













Thanks to the accepted answer that pointed me in the right direction.
I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :



# file: PROJECT_ROOT/.env
DATABASE_URL="sqlite:///../my_super.db"


But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:



PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26379145%2fsqlite3-pdo-no-such-table-though-it-does-exist%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote



    accepted










    The database that you have opened does not contain this table.



    SQLite will happily open any file name; if it does not exist, it will create a new, empty database.



    Check your database file name.






    share|improve this answer





















    • I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
      – Jeahel
      Oct 15 '14 at 11:04










    • The evidence shows that the database path you're using is not correct.
      – CL.
      Oct 15 '14 at 12:19






    • 1




      Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
      – Jeahel
      Oct 15 '14 at 15:34








    • 2




      A relative path is based on the current directory, which in PHP, is random.
      – CL.
      Oct 15 '14 at 17:44















    up vote
    5
    down vote



    accepted










    The database that you have opened does not contain this table.



    SQLite will happily open any file name; if it does not exist, it will create a new, empty database.



    Check your database file name.






    share|improve this answer





















    • I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
      – Jeahel
      Oct 15 '14 at 11:04










    • The evidence shows that the database path you're using is not correct.
      – CL.
      Oct 15 '14 at 12:19






    • 1




      Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
      – Jeahel
      Oct 15 '14 at 15:34








    • 2




      A relative path is based on the current directory, which in PHP, is random.
      – CL.
      Oct 15 '14 at 17:44













    up vote
    5
    down vote



    accepted







    up vote
    5
    down vote



    accepted






    The database that you have opened does not contain this table.



    SQLite will happily open any file name; if it does not exist, it will create a new, empty database.



    Check your database file name.






    share|improve this answer












    The database that you have opened does not contain this table.



    SQLite will happily open any file name; if it does not exist, it will create a new, empty database.



    Check your database file name.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 15 '14 at 10:23









    CL.

    134k12120153




    134k12120153












    • I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
      – Jeahel
      Oct 15 '14 at 11:04










    • The evidence shows that the database path you're using is not correct.
      – CL.
      Oct 15 '14 at 12:19






    • 1




      Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
      – Jeahel
      Oct 15 '14 at 15:34








    • 2




      A relative path is based on the current directory, which in PHP, is random.
      – CL.
      Oct 15 '14 at 17:44


















    • I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
      – Jeahel
      Oct 15 '14 at 11:04










    • The evidence shows that the database path you're using is not correct.
      – CL.
      Oct 15 '14 at 12:19






    • 1




      Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
      – Jeahel
      Oct 15 '14 at 15:34








    • 2




      A relative path is based on the current directory, which in PHP, is random.
      – CL.
      Oct 15 '14 at 17:44
















    I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
    – Jeahel
    Oct 15 '14 at 11:04




    I did not know about the automatic creation of the database, but mine is correct and exists. The app.db file is in the parent folder of the script containing the two lines I pasted. It seems to open it correctly because I have no other app.db file created anywhere.
    – Jeahel
    Oct 15 '14 at 11:04












    The evidence shows that the database path you're using is not correct.
    – CL.
    Oct 15 '14 at 12:19




    The evidence shows that the database path you're using is not correct.
    – CL.
    Oct 15 '14 at 12:19




    1




    1




    Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
    – Jeahel
    Oct 15 '14 at 15:34






    Well, I just tried with an absolute path to the .db file and it worked. I feel a bit stupid not to have tried this in first... But I wonder, what should be the reference with a relative path? Relative to the PHP script did not work as I tried it, but it surely was a path problem as an absolute path solved the problem. Anyway, thank you!
    – Jeahel
    Oct 15 '14 at 15:34






    2




    2




    A relative path is based on the current directory, which in PHP, is random.
    – CL.
    Oct 15 '14 at 17:44




    A relative path is based on the current directory, which in PHP, is random.
    – CL.
    Oct 15 '14 at 17:44












    up vote
    0
    down vote













    Thanks to the accepted answer that pointed me in the right direction.
    I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :



    # file: PROJECT_ROOT/.env
    DATABASE_URL="sqlite:///../my_super.db"


    But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:



    PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql






    share|improve this answer

























      up vote
      0
      down vote













      Thanks to the accepted answer that pointed me in the right direction.
      I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :



      # file: PROJECT_ROOT/.env
      DATABASE_URL="sqlite:///../my_super.db"


      But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:



      PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Thanks to the accepted answer that pointed me in the right direction.
        I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :



        # file: PROJECT_ROOT/.env
        DATABASE_URL="sqlite:///../my_super.db"


        But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:



        PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql






        share|improve this answer












        Thanks to the accepted answer that pointed me in the right direction.
        I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :



        # file: PROJECT_ROOT/.env
        DATABASE_URL="sqlite:///../my_super.db"


        But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:



        PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 at 16:08









        gogaz

        1,578919




        1,578919






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f26379145%2fsqlite3-pdo-no-such-table-though-it-does-exist%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            How to ignore python UserWarning in pytest?

            Alexandru Averescu