1

I am researching converting a php/mysql web application I have, into a stand alone desktop application using NW.js (node-webkit), php-webkit, and a sqlite3 db in place of Mysql.

I have successfully installed all the necessary components to establish a sqlite3 connection and retrieve values from the database using similar examples to the ones found here: https://www.npmjs.com/package/sqlite3

The sqlite connection and retrieval of data works fine via the javascript examples.

Although when I try to connect to the same database from one of my PHP pages, no results are produced.

Is it not possible to connect to and retrieve info from my sqlite3 db from the PHP pages within a Node Webkit project running php-webkit? Has anyone successfully accomplished this, or is what I am trying to do essentially not possible?

Andrew
  • 50
  • 7
  • i've never used phpWebkit but just incase keep this in mind: sqlite can support multiple connections for reading but you cannot write to the database from mulitple connections. for more info,read [this](http://www.sqlite.org/faq.html#q5) – miqe Jul 21 '15 at 17:52
  • Thanks Mike, that is good to know. Fortunately with this desktop version of my web app, I will not be writing to sqlite in any case. – Andrew Aug 04 '15 at 00:13

2 Answers2

1

I am the author of php-webkit. PHP is packaged with a copy of sqlite and php-webkit works with this. If you are having issues make sure the copy of PHP you included has the sqlite extension and sqlite enabled in your PHP.ini. Connecting to a stand alone copy of sqlite should be possible with the sqlite PHP extension. Here are some examples of connecting to sqlite from php.

Community
  • 1
  • 1
Bacon Brad
  • 308
  • 3
  • 18
  • Thanks Brad. Please make a tutorial video about Php-Webkit. – namal Aug 19 '15 at 13:38
  • No problem. Unfortunately my time on side projects is limited and I don't think I will be able to make a video. I am in talks with another dev that plans on taking over php-webkit and I will let him know though. – Bacon Brad Aug 19 '15 at 15:29
  • Hi Brad, first thanks very much for php-webkit! Also thanks for responding. It appears all was working well with php-webkit and indeed sqlite access is working just fine from my php pages. The issue I was experiencing was a bit of old Javascript that caused my application to choke, and not load and code afterwards properly. Once I located and removed that, sqlite access worked as expected. – Andrew Aug 21 '15 at 16:14
0

It seems that it is not planned to access the db through php-webkit. What you can do is access the db through javascript and put the values in the desires divs that you created with php.

<?php
echo '<div id="insert">'; 
echo '</div>'; 
?> 

And then use jquery or javascript to insert something that you got form the db.

var db = openSQL(); //method to open a connection to SQLITE
db.serialize(function() {
    db.each("SELECT input FROM table", function(err, row) {
        $('#insert').append(row.input); 
    });
});
db.close();
Silve2611
  • 2,198
  • 2
  • 34
  • 55
  • Thanks Silve, very nice example for accessing sqlite through JS in nw.js. Actually it appears I was suffering from a bad case of YDIW. It appears some really old javascript I was using, was blocking some other functions on the page, causing sqlite to not be accessed from PHP. Yet when I removed that aging code, Voila! PHP accesses my sqlite Database as expected. – Andrew Aug 04 '15 at 00:20