Pure PHP implementation of SQLite? - php

Is there a pure PHP implementation of SQLite that will run on PHP 5.1.6? I am working on an application that would benefit from being able to store data in a relational database, but the server that it has to run on is stuck with PHP 5.1.6 and has been configured "'--without-sqlite"
I have no control over this server; cannot recompile, upgrade or otherwise modify PHP aside from using .htaccess files. Hosting externally is also not an option, unfortunately. MySQL may be possible but would be a nightmare trying to get their IT to create a database for me. (It took them 6 weeks to get .htaccess files enabled because of red tape and other things)
Am I out of luck? My fall back is to write everything to flat files but I really would rather not do that.
EDIT: Fixed typo. PHP does not have the SQLite extension and was configured "'--without-sqlite" according to the output of phpinfo()

Actually, you could easily download and install sqlite in your userspace, whether on windows or on a linux remote shell doesn t usually matter unless your host is unusually restrictive, if that is the case you should change service provider.
Once sqlite is installed, you can one of the available pear extensions or pecl extension to allow easy access through php.
Tutorial and code examples for the pear solution here.

Related

How easy is it to use PHP on an MS Server with MS SQL?

I generally use linux servers and program in PHP (plus other associated technologies) with mysql databases. A client has existing ASP sites using MSSQL databases on a Windows server and wants some new sites created on their server using their MSSQL database as the main data source. I have used ASP in the past but much prefer PHP so would rather use this.
I just wanted to confirm that i'm right in saying as long as the server has PHP installed (which it does) then there's no reason I can't create a PHP site on the Windows server and just use different connectors to connect to the MSSQL db (rather than what i would usually use for connecting to a MYSQL db). Presumably (other than the different connect/query code) this would work in pretty much the same way as with a linux setup with mysql and i could then code the site in PHP but use their existing datasource?
I would be extremely grateful if anyone could confirm i'm right in saying this and if there's any other issues that might cause any problems?
Thanks so much for your help as ever,
Dave
You can enable MSSQL support in PHP on Windows. The default Windows PHP install has the php_mssql.dll extension commented out in the php.ini file. Uncomment that line, restart Apache, and it should work.
There is a supporting DLL called ntwdblib.dll that you may need to find a replacement for, as the version included with PHP may be outdated and won't work with newer versions of SQL Server. (I had this problem when setting it up.)
There are two different libraries to connect to SQL Server from PHP:
The legacy mssql extension, which has been discontinued on Windows
Microsoft's sqlsrv extension, which only works on Windows
I've basically worked with the second one and I can say it's a very interesting product. It's robust, it has a very nice interface and it's totally up-to-date. But what I like most is that it has very nice features. E.g.:
It can return dates as PHP DateTime objects
It provides a PDO driver
The only drawback of using SQL Server is that there isn't an easy way to write a cross-platform app but I understand it isn't problem in your case.
Yes, it is rather straight forweard.
You need to have the mssql library activated in php.ini. Which can be troublesom.
MSSSQL docmentation

how to start php?

I am asp.net developer , i want to learn php
what are the software need to run compile php file ?
how to install this software any path that should be set ?
what kind of database it needs to store data and retrieve date ?
see me as beginner and then give the idea / information ..........
thanxx
You just need the PHP interpreter and if you want to do web stuff a webserver.
You can get the interpreter from http://www.php.net - if you are using windows you really want to get a binary version and not compile it on your own - and the Apache webserver.
As a database PHP developers usually use MySQL (but it can also connect to most other databases).
The easiest way for your to get started is getting a package like XAMPP which will contain all you need without requiring you to configure everything manually.
For actually learning PHP, please get a recent book/tutorial. Old stuff is usually telling people to do horribly things every sane developer will hate you for (cluttering your global namespace with variables settable by the user for example).
You could have a look at the official PHP docs which also contains a "getting started" guide.
Since you are an ASP.NET developer I assume that you are familiar with IIS and that you're probably using IIS 7.5. If so then the easiest way to familiarize yourself with PHP is to use Microsoft Web Platform Installer and install PHP directly to IIS. You don't have to set any paths after that, just create a site on IIS and start putting PHP files there. Keep in mind that Web Platform Installer automatically enables WinCache extension and your changes might not be there when you hit the refresh button. Just locate the php.ini and comment out the relevant line.
Straight from the horses mouth. Getting Started. You will need a php interpreter, if you have access to a webhost that has php installed you're half way there, if you have a linux partition you're half way there, otherwise check out XAMPP.
Software: XAMPP will get you up and running
Tutorial: w3schools
If you are familiar with IIS and want to use it as your web server you can download PHP for IIS here and use some of the learning material there to get started.
If you did not want to use IIS and wanted to use Apache instead then I agree with the others XAMPP will get you a dev environment up and running quickly.

Sqlite3, apache users, and easy installs

I'm writing a small app that needs to have a super easy install process. Version one used a csv file instead of a database, so priority #1 for v2 is getting sqlite going instead. I've used sqlite a lot with Ruby, and love it, but this is my first time using it with PHP.
Basically, in order to get SQlite3 to be able to insert into the db, I needed to make both the database.sqlite3 file and the folder containing it owned by the apache user. From reading the docs, this seems normal.
However, apache isn't always going to be running as the same user. Here, it's 'http', but I know on Ubuntu it's 'www-data', right?
So, is there a good way to detect the username Apache is running as, and changing it, or am I going about this wrong? It needs to be something I can just put in the install script, as the people who use this app don't know or care anything about tiny details like this.
Thanks.
I believe you're going at it from the wrong side: you need the SQLite db to be writable by the PHP script, as I understand the matter, and this might not be the same as the Apache user.
If PHP is installed as an Apache module it will inherit the Apache user, but a much more common case on shared servers is to have PHP set up as CGI under suphp or phpsuexec, so the scripts run with the permissions of the user himself.
I'd suggest you write an install.php script to create the folder and the database, so both will inherit the script's permissions, no matter which user it is. Look into the manual for mkdir() and sqlite_open(). If nothing else works there's always chmod().
As you specifically cite SQLite v. 3 you may want to check the server version with phpversion(); in PHP 5.3 sqlite_* functions do work with version 3, PHP 5.2 and below understand version 2 instead. To use version 3 in PHP 5.2 you must use pdo_sqlite.

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

Best PHP download to keep all my options open?

In the past, I used WAMPserver on windows to parse PHP for me. This is a pre-configured package, focussed on working with MySQL.
When I tried to run PostgreSQL, I got error messages that said that my version of PHP wasn't compiled to work with PostgreSQL.
So, I've recently uninstalled WAMP and every associated with it. I've downloaded Apache 2.2.11 with openSSL, installed as admin(you know, run the command prompt as administrator, cd to the directory where the download was done and have it executed, so the install was done as admin).
That's that. I now have Apache installed, "it works" shows up, so I'm that far.
Now I'm wondering, do I download the exe and install, or the zip, or something else.
What is the best thing to do to make sure that the PHP on my system can handle everything I can ever throw at it?
Also, PHP first, or MySQL/Postgre first.
And lastly, what about PEAR? I need PEAR installed, which isn't standard on Windows. I'm guessing the pear.bat file in the PHP downloads will do that for me?
EDIT: I see one close vote, yet no comment as to why. It makes me wonder how people who are so lazy and rude got to have somany points.
I would recommend downloading the zip package, as configuring php is not really that difficult, and it allows you to add features as needed.
As for whether first to install php or MySQL/PostgreSQL, - it does not really matter. You can install them in any order.
Your guess regarding PEAR is quite correct
i haven't used wamp before, so i can't comment on that
i do however use xampp which sounds very similar
in xampp if i want to enable postgres support i edit the php.ini file and uncomment the postgres section of the ini file, same with any of the extensions that i need
perhaps this might be an alternative you can try if you get stuck
There are many ways to setup a HTTP server/PHP/database machine. Sometimes the behaviour of your development setup will differ from the live server's.
I would recommend finding out the setup your web host is using, then getting a vmware appliance image that fits that as close as possible and get any additional software using it's package manager (which is easier that installing stuff on Windows).
Setup a file sharing link between the VM and the host, make sure you can view the VM's port 80 in a browser running in your host OS and you're set.

Categories