there are already some applications available which "understand" the mysql protocol and to which it's possible to connect using a mysql client -- for example: you can connect to the sphinx search engine using the (an) mysql client, mysql-proxy understands the mysql-protocol, too. etc.
now i wonder if there is an implementation available in/for PHP so you could connect to some server-application implemented in PHP using the mysql client? i am looking for some PHP library (or extension) which implements the mysql protocol.
thanks,
harald
I'm not aware of an existing pure php implementation of a mysql server. I expect it would be slower than a C/C++ counterpart. Additionally, php has always been annoying to run as a daemon.
However, should you wish to implement a server, you may wish to look at http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol. It defines the protocol for client-server communications.
There are some software available that seems to do what we need. I did not use them yet, but eager to try, so I'll get back to you later.
DBIx:MyServer in Perl
MyProto in Erlang
MySQL Proxy in C/lua
Do you mean a scenario like: You have a system, that does not have a mysql library but you want to be able to talk to the mysql server. To do that, you want to use PHP as a proxy to talk to the database?
If your existing system can do http requests, you might want to create a restful service in php and access that restfull service. PHPRest might be what you are looking for.
Keep in mind, that this is probably slow, compared to a direct database call.
There are built-in mySQL client functions in PHP:
manual
is that what you mean?
Related
As the question says, is it possible to interact with a MySQL database created with XAMPP (so, using PhpMyAdmin) without using PHP, but only Javascript/JQuery?
This is a merely theoretical question, I don't want to know how to (but if you know it, I want discard your help).
With this, I don't mean using Ajax to send my request to a .php page that will then interact with the database, but directly interacting without passing through PHP.
In terms of a PHP application, it's not possible to interact with MySQL through JavaScript because JavaScript is executed client side i.e in the browser, it doesn't have access to anything on the server it is being served from.
However, with nodejs - a JavaScript runtime built on Chrome's V8 JavaScript engine - you can write a complete JavaScript server side application without having to touch PHP. There's a node-mysql module which means you can interact with a MySQL database with JavaScript code.
Several web application frameworks exist to help you get something up and running like Express, which saves you the burden of having to write up things like routing logic.
No you can't interact with MySQL through JavaScript or JQuery. You could use JavaScript and JQuery through your PHP pages if that would be a functionality you'd be interested in. You could also use another language compatible with MySQL. Otherwise interacting with MySQL straight through JavaScript/JQuery won't work.
You can do openDatabase()
Make an SQL file, db.sql,
and in a javscript file, type this: openDatabase(db.sql, '1.0', 'My First Database', 65535)
More on this here: http://html5doctor.com/introducing-web-sql-databases/.
This makes an SQLite connection. I recommend it as it doesn't use PHP, but if you really really want to use MySQL(Again, I recommend using this SQLite method) you have to use PHP or some sort of server scripting language.
Learn SQLite: https://www.tutorialspoint.com/sqlite/index.htm
This works on:
XAMPP
repl.it
well, basically anything.
Is it possible to send data from C++ to PHP? I have wrote a server in C++ that connects to a database, and I was wondering if it is possible at all to use the socket library built into PHP to connect to the socket server written in C++. Would it just be PHP itself? I mean, would I not use JavaScript (AJAX) to call a PHP script that might do the socket work?
Basically, how do Google do this? I know some of their applications use C++/Java as their back-end, but is there any performance at all?
For those wondering why I am asking this question, then the answer is I don't want to rely on PHP to handle data as I am writing a game. I would like PHP to handle the web part, but not necessarily the game client so-to-speak; and I just think C++ would be a lot efficient at sending and receiving data to store in the database.
Has anyone done something like this and if so did you run into problems; and is this a practical solution at all?
Thanks.
Google use protocol buffers for data exchange between different services. Facebook has Thrift. Etc, etc. There's a plenty of protocols and libraries for you to choose from, but I'm afraid you'll have to do the research yourself.
Last time we had such a task (connecting C++ backends with PHP frontend), we wrote our own, very simple protocol. It's not that hard, in fact, it might be easier than implementing some abstraction on both sides.
I want to create http socket connection for server in php for multiple client . how can I do that ? I need some resource .
First I was trying to create server in java .I create a server in java . And trying to reach from android application .But server can't find any client.But when I create client in java .It was working. How can I solve that problem ???
Take a look at this article:
Writing Socket Servers in PHP by Zend
Also give a try with Google:
http://www.google.com/search?aq=0&oq=php+socket+server+mul&sourceid=chrome&ie=UTF-8&q=php+socket+server+multiple+clients
Personally I think this would be a pretty bad idea, as already mentioned it lacks Threading and it's Socket support (imo) isn't really that adaptable.
The only plus side is that you can use fork to fork off another PHP process to handle a client, but you're getting very complex.
Another language would be much more suited for this type of development.
Note that even if you did do this in PHP, you'd probably have to rely on external services anyway, and possibly even end up writing at least some code in another language anyway.
You're trying to use PHP to do what? Mind you, I like PHP and work with it almost every day, but please do remember PHP in and on itself is based on request and response, and not very suitable for long running processes. In a manner of exercise, it might be interesting, but if you're trying to write a webserver from scratch using PHP, you might want to reconsider your choice of language.
That said, you can create a socket acting as a server, and listen to incoming packets. I do still think you're reinventing the wheel though.
though i love php and java, i wrote my socket servers in c++ running under lamp in an amazon ec2 cloud server. it is very, very simple to code and debug and safe and you can practically just copy/paste examples.
in the long run, i will probably develop a java solution because of portability and scalability, but the initial effort to get a c++ solution working is just so much less than implementing a java solution...
the first thing you must ascertain (find out) is whether your server allows you to open custom ports. amazon ec2 does and at this point in time (feb13), can be used for free for 12 months.
so, this is for you if you are in a hurry:
this here set of examples has all that you need to be up and running in no time.
Judging from the question title (the rest only makes it more confusing) you could use an existing package like http://pear.php.net/package/HTTP_Server to implement a webserver in PHP. It already contains all the socket code to accept client connections and stuff.
So what i have to do to find the server from different client
"Finding" is too broad a topic. Depends on your actual setting. On a LAN there are some protocols for discoverability. Otherwise you should just rely on a fixed machine name and port number for your instantiated server. You can connect to it as e.g. http://localhost:8007/ or whatever you've predefined.
If possible, how can I get (and post) data from a mysql database using javascript? I know I can use php and other languages, but I just need to know if this is possible with javascript?
Thanks in advance.
That's not possible with Javascript. I could not find this with server-side javascript too.
Not sure about your exact requirement, but you can use Ajax to interact with database though some server side language.
If by Javascript you mean NodeJS on the server, this project might interest you http://github.com/sidorares/nodejs-mysql-native - however the answers above are correct if you are talking about Javascript running inside a browser or other container.
If you want to run a vanilla javascript (for the concurrency speed) inside your own engine, I recommend looking at NodeJS and then using the NodeJS MySQL Native Driver that I linked above.
• http://github.com/sidorares/nodejs-mysql-native
Judging from the "iPhone" and "Android" tags, I guess, you are trying to access the local storage databases on these platforms.
They don't use MySQL, but SQLite.
How you access them from the mobile browsers is described in the W3C draft documents for the local storage: http://dev.w3.org/html5/webstorage/ for the local storage API or http://www.whatwg.org/specs/web-apps/current-work/multipage/section-sql.html#sql for the SQL API. It should be roughly the same API on iOS and Android since both of them use the Webkit browser engine.
it is not possible, javascript is executed on the client.
you could make the javascript call something on the server (e.g. php script) that access the database though.
The Web SQL database API isn’t actually part of the HTML5 specification, but it is part of the suite of specifications that allows us developers to build fully fledged web applications, so it’s about time we dig in and check it out.
Some examples are here
http://html5doctor.com/introducing-web-sql-databases/
Do remove the tags iphone and android from this question. the tags are not relevant.
And only with javascript you cant accompolish this task , GET and POST request can be handled only by server side scripting languages like php.
Refer : http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml
javascript can get database from server
if use AJAX , only a way is AJAX
I'm working on a project that involves a database (My SQL), website (PHP) and a custom high performance server application (C++). The C++ application (and its accompanying client application) make up the main bulk of the project, with the database storing long term data for it. The website is primarily for displaying various statistics, and administration.
1) I want the PHP scripts and c++ application to be able to communicate in some way, since the database is only used for persistent data, and additionally the c++ application may cache some things so needs to be told to reload the data in some cases. It is highly likely they will be on different machines, and even possibly different OS's. I've been considering the idea that TCP may be the best option with some simple command - response protocol?
2) What is the best way to write the common database interface code once, and be able to use it from both the PHP website and the c++ applications?
1) Use the database to communicate. The C++ application can
select * from table where some_last_modified_timestamp > '<last time checked>';
2) Use stored procedures in preference to hardcoded queries both in PHP and C++.
You might try not allowing PHP to access the database at all. Make the C++ app do all the database work, and make it serve data to the PHP site. You could run part of the C++ app as a server for the PHP to fetch reports etc from it.
#1: If you're on different OSes, then TCP sounds like a decent idea.
#2: Sounds like you need a C library, and then call that from both C++ (trivial) and PHP. A search on Google returns lots of articles about writing PHP extensions in C, for example:
http://devzone.zend.com/article/1021
http://www.devarticles.com/c/a/Cplusplus/Developing-Custom-PHP-Extensions-Part-1/
1) I would also suggest TCP. Depending on the complexity of request-response I'd probably pick either some ad-hoc text protocol or use XML (especially suitable if responses or requests are structured and more complex). If you use XML you won't need to write your own parsers/generators. You could even try using XML-RPC but I have no practical experience with that yet.
Best way to use the same SQL in both PHP and C++ is prepared statements.
A good way to communicate is for one to host a server (custom/soap/rest) which the other connects to. PHP can easily both host and connect, and since that code is written in C it should be easy in C++ too.
Writing a PHP extension like Eric Seppanen suggest is way beyond the scope and need of your project Id say.
Use Thrift or Protobufs (possibly Avro) to declare a communication protocol and use that over a tcp socket. It'll solve your cross language problems without having to roll a custom protocol, and you end up with actual objects on both sides (statically typed for c++!). I've seen Thrift used like this very successfully.
My approach is to use SWIG. I use it with python, but it supports PHP also.
Then it's very easy to use it from your script.
Other solutions could be some RPC (wich would allow to have the server and the PHP application in different places).
I am a beginner here, so please excuse if my idea is terribly bad.
But why cant we just transfer XML over TCP. Have a C++ TCP server and PHP TCP Client. I think PHP has a pretty powerful socket APIs