I have started to try out noSQL databases now and are currently testing out couchDB. Seems like a good solution, but I really get some headache when I follow available examples on how to create views (queries) to select documents from a database and sort them.
Everything I can find is regarding JavaScript and it would be great to take part of some examples for PHP since that is the language we will use.
So, how do I create views using PHP for couchDB?
As far as I know, the equivalent of the SQL language that would be used for a relationnal database is, for CouchDB, Javascript.
So, if you want to create some "query", or "view", you have to do it in that language : it's the one that's understood by CouchDb.
PHP and CouchDb are totally independant : the only thing is that :
PHP can send requests to CouchDb
and get results
But what happens on the CouchDb side is independant of your PHP script -- and there is no PHP on the CouchDb side.
The only way to filter results using PHP would be to :
Request more data from CouchDb than you need
And throw away, from PHP, what's not needed
But, obviously, that would not be an efficient solution...
Javascript is privileged as a CouchDB view server only because that's what's bundled with CouchDB. There are view server implementations for many other languages/runtimes, including PHP.
JavaScript (CouchDB native)
Common Lisp
PHP
Ruby (fork)
Python
couchdb-python
couchdb-pythonviews
Erlang
built-in view server
erlview
Clojure
Perl
Chicken Scheme
Coldfusion
Haskell
OCaml
I think you need to understand Javascript's stance in CouchDB. Javascript isn't a target language like PHP, Ruby, etc. Javascript is more equivalent to SQL here. The javascript is server-side and CouchDB itself actually executes it. This is what you use to do map/reduce and build views and such.
Try PHPillow man
Here's a very short introduction to it: http://www.catswhocode.com/blog/getting-started-with-couchdb-tutorial-a-beginners-guide
If you check out the SVN of PHPillow, there's more information in the 'docs' folder
Related
I am working on making a search engine, I have to store multiple data against one word, how it will be done using php without use of JSON.
and is it a good approach to do this work in php or I should switch to another Object Oriented Programming Language ?
If its research project, you could give a shot with PHP7 (its faster). PHP5 will also let you achive what you want.
What language you chose is mainly dependand on what you want to achieve. C++ is surely faster than PHP.
Also you would need to check about bigdata handling and non-relational databases (MongoDB for example) which are scalable.
PHP has embedded V8 JavaScript engine, http://www.php.net/manual/en/book.v8js.php. I was wondering what are possible use cases, esp. considering that PHP is synchronous and JavaScript is asynchronous.
A powerful feature of this extension is that the same code can be used both client and server side, reusing implementations of the same code in PHP for server side and js client side.
A possible use case is for providing server and client side validation using the same JS code. Client side, the code would be run in the browser, and server side it's executed using V8JS.
Other potential uses could be templates or any other business logic that's needed both client and server side.
It seems like you'll still be in uncharted territory here, though. I haven't seen any libraries use V8JS for anything like this.
One of the ways I am using JS integration within PHP is to provide a simple manner for end users to safely execute user-supplied code (a.k.a. scripts) within a PHP-based app. With the implicit isolation, one can limit the inputs and functions available to protect both user privacy and system security while allowing a wide range of user-defined scripted actions within the server context.
I must admit that seeing executable javascript code in database records is a bit unnerving at times! You do get over it though. :)
One use case could be server-side rendering for javascript templates or frameworks, SSR for short.
One could write their templates with a javascript framework like Vue.js or react and render it with v8js.
Once php has rendered the template and sent it to the browser the javascript framework could pick this up and make it interactive.
Two benefits here are faster loading web apps and no annoying javascript page flicker.
For building crawler which extracts useful data from HTML emulating Javascript runtime is especially useful, because some HTML data may be hidden/mangled by Javascript code. So unless you would like to write Javascript parser in PHP yourself - the only option is to use V8 engine built already with that purpose.
PHP and Javascript are languages, it doesn't make sense to say one is synchronous and one is not. Informally when one says that, they mean that most of the libraries around that language that use I/O use async/sync IO.
In the core language and V8, nothing is asynchronous.
Why to use it? Javascript on V8 is orders of magnitude faster than the canonical PHP implementation (note that there are other PHP implementations, like Facebook's HHVM) while still being just as powerful scripting language. Normally you would be forced to write a C extension for PHP to get raw performance.
Sorry to bump / add to an ancient question, but a fairly obvious use case in the Web 2.0 / 3.0 era is going to be "when file_get_contents() just won't cut it."
Although it may not be the best choice, PHP also isn't the worst choice for bots, spiders, scrapers, etc. And more and more web pages aren't complete unless the JavaScript on them is executed / rendered.
I am totally new to PHP, I want to know whats the difference between PHP,CakePHP and Joomla.
Which IDE is most commonly used for developing PHP based web applications.
How Ajax is implemented in PHP, is it through JQuery only or there's something more to it.
Which will be the ideal book that covers most of the basic and advance concepts.
PHP is a programming language.
CakePHP is a framework written in PHP.
Frameworks establish a basis for quickly developing applications by providing you with a lot of functionality that you would have to write in plain PHP for most applications anyway. For example, secure database access, session management or pagination. These are all tedious things you have to care about, but that are basically the same for every app. It also establishes a certain structure for your project.
Joomla is a CMS, a content management system, written in PHP.
CMSes are pre-built systems you can use as-is, that allow you to manage your content. They're extensible and customizable, but often not to the degree that an app written in plain PHP or using a framework can afford, or not easily so. There's a lot of functionality in there already though that you don't need to write at all.
AJAX is not implemented in PHP at all.
AJAX just means that Javascript asks your server for data and the server delivers it.
A typical PHP page responds to requests with a complete HTML webpage. For AJAX requests your server instead responds with XML, JSON or plain text, whatever you decide. It works exactly the same way as responding with an HTML page.
Javascript is a programming language.
jQuery is a library written in Javascript.
See framework, the definition is almost the same.
For IDE recommendations, do a search.
PHP is a programming language
CakePHP is a framework
joomla is a CMS
AJAX - php is executed server-side and as such isn't something "implementing" ajax. The original call comes from client-side javascript that is not limited to JQuery. JQuery is a javascript library.
Ajax isn't implemented in PHP. Ajax is client-side technology. PHP is server-side. I started using Eclipse's PHP IDE, but I found the debugger to be more of a hassle than it was worth. I'm still using the IDE, but I'd probably be just as well off with a plain text editor.
You might want to check out Zend (www.zend.com). Most of their tools are commercial based, but they have some free tools that help you run PHP on your own machine.
I don't personally use a PHP framework, so someone else will have to help you with that one.
When I was first introduced to PHP, I was directed to these free instructional videos.
While they don't directly address your question, I'd be wrong to not perpetuate the kindness by sharing them with a new, novice enthusiast.
Good luck!
You are asking a lot of questions at once, which are fairly simple questions but the real answer is you need to learn a bit more about web development in general in order to give yourself a broad knowledge of the web development ecosystem. Stack Overflow is not good at giving you 'how do I program in PHP', it's better for specific questions like 'how do I sort an array by string size' or something like that. For learning how to program, you need to learn this yourself.
The wikipedia page on web development gives a very broad overview of how things like server-side, client-side etc fit together - so broad as to not be particularly useful for those wanting to achieve anything in particular, but suitable for people coming across web development from not knowing the difference between an application and a programming language. An equally broad knowledge of http is also helpful, and since you brought it up, it also looks like you are having difficulty understanding what ajax is.
For PHP specifically, the PHP manual contains everything you need for all but the most obscure questions, providing you have picked up a few programming skills already - and if not, I recommend you take a course or something, since if you haven't been programming since you were a child you probably won't take to this kind of thing quickly.
A little-known but powerful solution for AJAX in PHP is Xajax. It allows you to call PHP functions asynchronously as AJAX calls, making it by far the most familiar solution for people familiar with PHP but not Javascript.
Beware, however, that a huge portion of the users are based in Europe so the help forum can be VERY difficult to understand and official documentation is similarly spotty.
I personally always advise against using a book to learn--stick to quality websites (which ones become very obvious very quickly) By the time something is put into print, it's usually out of date or has been superseded by better technique. While the basics don't change much, there are many day-to-day things that experienced developers use regularly that you won't find in a book. I also advise learning the basics of development first (object oriented theory, logic progression, arrays, etc) before learning the specifics of any language. PHP.net can define specifics all day, but it's far more difficult and time consuming to learn MVC theory on the fly. Finally, if you have some money, I can't say enough good about Zend's certification training.
Here's my background:
Decent experience with PHP/MySql.
Beginner's experience with OOP
Why I want to learn Python Django?
I gave in, based on many searches on SO and reading over some of the answers, Python is a great, clean, and structured language to learn. And with the framework Django, it's easier to write codes that are shorter than with PHP
Questions
Can i do everything in Django as in PHP?
Is Django a "big" hit in web development as PHP? I know Python is a
great general-purpose language but I'm
focused on web development and would
like to know how Django ranks in terms
of web development.
With PHP, PHP and Mysql are VERY closely related, is there a close relation between Django and Mysql?
In PHP, you can easily switch between HTML, CSS, PHP all in one script. Does Python offer this type of ease between other languages? Or how do I incorporate HTML, CSS, javascript along with Python?
Can i do everything in Django as in PHP?
Always
Is Django a "big" hit in web development as PHP?
Only time will tell.
With PHP, PHP and Mysql are VERY closely related, is there a close relation between Django and Mysql?
Django supports several RDBMS interfaces. MySQL is popular, so is SQLite and Postgres.
In PHP, you can easily switch between HTML, CSS, PHP all in one script.
That doesn't really apply at all to Django.
Or how do I incorporate HTML, CSS, javascript along with Python?
Actually do the Django tutorial. You'll see how the presentation (via HTML created by templates) and the processing (via Python view functions) fit together. It's not like PHP.
Yes.
It's very hard to tell exactly how popular it is.
MySQL is officially supported.
Yes, but probably not in the way you think. Please read this and also follow the tutorial that S.Lott mentions.
No. You can only do a LOT better.
Awesome, popular. Supported by best hosters like Mediatemple.
No. You can just change 'mysql' to 'postgresql' or 'sqlite' in your settings.py.
NO! Python would never give you the right to mix up everything in one file and make the shittest shit in the world. Templates, static server.
Django is a Model-Template-View framework, great for any applications, from small to huge. PHP works fine only with small apps. Yeah, PHP == Personal Home Page, lol.
P.S. Also you can minify your CSS and JS. And compile to one single file (one js, one css). All with django-assets. And yeah, there's a lot more reusable Django apps (for registration, twi/facebook/openid auth, oembed, other stuff). Just search Bitbucket and Github for "django". No need to reinvent a bicycle, like you do with PHP.
In PHP, you can easily switch between
HTML, CSS, PHP all in one script. Does
Python offer this type of ease between
other languages? Or how do I
incorporate HTML, CSS, javascript
along with Python?
That's one of the reasons why PHP is so easy to learn. And it's also exactly why so many (if not most) PHP projects are such a complete mess. It's what leads to the "spaghetti code" syndrome.
Django is all about complete separation of page design from view logic from URL routing (in fact this is true of most modern MVC or MTV frameworks). So templates are in one place, data structure definitions are in another, and the logic that defines their interaction is in another. It takes a bit of getting used to, but has a huge payoff.
Another thing that takes getting used to for people coming from PHP is that fact that file and foldernames no longer have a direct bearing on the URL. For example in PHP, you might have foldername/filename.php and the URL would be http://example.com/foldername/filename.php. It doesn't work like that in Django. Instead, you define a URL structure in a file (urls.py). In that "map" you define which piece of logic ("view code") will be called when a matching URL is intercepted. Everything is abstracted like that. The result is a much cleaner, more logical site layout and logic.
What's the best Ajax library for PHP and why do you prefer it?
If you are searching for a library to facilitate Ajax Requests, it is not dependant of the server-side : launching Ajax requests is done on the client-side, in Javascript.
There are plenty of JS Frameworks to do lots of nice things, and, in the middle of those, Ajax Requests.
I've used those ones :
prototype : the one I know the best ; and really like it
jQuery : probably the most used nowadays
MooTools
On the server-side, the JS Framework used doesn't make much different.
You might still want to take a look at the JSON format, which is great to exchange data between client and server when doing Ajax requests. There are several implementations in PHP that allows you to work with that one.
For instance :
With PHP >= 5.2 : json_encode and json_decode ; nice, as provided by PHP
Zend Framework has Zend_Json ; I've already used it on a PHP 5.1 server, outside of Zend Framework ; nice because I like ZF, and this component works on 5.1
If you want other informations, you might edit your question, to be more clear about what you want :-)
For getting data out of PHP — http://uk3.php.net/json
For abstracting XMLHttpRequest in a cross browser fashion, converting JSON to JavaScript objects, and providing ways to insert that data into a document, I tend towards YUI, but this is largely a matter of personal taste.
It's depends on needs, but JSON is also worth a dig;
http://json.org