C++ Program Calls PHP Script To Upload Content to Database - php

Say I have a C++ program that any user can download on their machine. I'd like to give the user the capability to upload content via this program to some remote database that I've set up.
My strategy is to have the C++ program call a PHP script that will connect to the database when prompted. However when I attempt to connect to a remote server that isn't localhost like the following call:
mysql_connect("website.com", "user", "pass");
It gives the error:
PHP Warning: mysql_connect(): Lost connection to MySQL server at 'reading initial
communication packet', system error: 111
Is there some way to allow any user who downloads this program the ability to connect and upload content? Further more, is there a better way that could also work? Thanks.

If you want to directly upload from the user's machine why use PHP? Use the mysql C API. Just enable remote access in the mysql server.
But I won't advise to do that, it's better to have your own webserver, with it's "local" mysql, and then you won't have connection problems and expose your DB server to the outer world.

Related

I would like to access a local mysql database through my php script hosted on a remote server

I would like to access a local mysql database through my php script hosted on a remote server. Is there a way to code a script, that I save on the local mashine, and receives queries from my remote php script, executes, and the results are submitted back to the script?
How is this technology called?
I know, that I could just open the mysql port on my firewall, but I don't want to do that.
The technology is called AJAX.

A Php server using sockets or connect to the database

Connecting to the database at each request can be expensive the solution to that could be using memcached. However i have been working on a php socket server that will be available in the background to fetch data from. This way on my php server i can fetch all the data i need and on the web request connect to it and retrieve the data without having to go through the data base.
I couldn't find any data on this so my question is how expensive is it to connect to my php server using sockets. Is there a down side to it?
Note: The php socket server is running on the same machine and will be able to serve multiple applications.

how to connect a php exe to an online sql server using ZZEE PHPExe

i am trying to create a php.exe file using ZZEE PHPExe but my problem is that my database is hosted online from justhost, when i try to connect using the compiled php.exe it always gives me errors, i wasn't able to connect to my database at justhost, is there any php compiler that will allow me to connect to my online database? what will be the best choice for a compiler ?

Can php or javascript on client link to remote server database?

I have access to a remote Oracle database when using Toad or SQL Developer.
The connection is specified by a TNS record and user+password of course.
Now I wish to have a local webpage that shows (regularly refreshed) data from the database. At first I was thinking of using php but I guess that can only be used on the server itself and I am unable to create files on the server. Of course a server page would be more suitable when there's multiple users but here there's only one.
In fact I just want to do the same as is done by running queries from the tools mentioned, but now called from a custom webpage. I feel this should be possible because the tool has to establish the connection from client to server db also; but I don't know how to set up my local client webpage(s).
Is this possible by applying php or javascript if that's more suitable?
Well you have to understand that the functionality of connecting to oracle database is packaged as part of frameworks, there are no such frameworks in javascript which can help you.
you are right with php, however it needs a webserver to run and they are free :)
the reason why php can connect to oracle database is, it has the framework to do those operations.
for now the answer is no.
or you can see if you can write an Activex which can connect to Oracle database and refresh, microsoft provides framework / api to connect to databases
The best way to do that kind of thing is AJAX: a javascript code calls a PHP page on the web server, this page connects to the DB and returns data to the javascript that updates the page.

How does the connection between mySQL and a Php website work?

I have successfully setup a localhost (Individual Installs) with Apache 2.2, MySQL and PHP, as well as setup a couple virtual-hosts. Currently, I am trying to teach myself command line in MySQL. The part I am lost on is setting up the connection between the database that I create and the virtual-host website I am working on. In my mind I would want to save the database for a specific website in the same folder that I am creating the website. However, I could be way off base. Could some body explain how this piece of the puzzle and how it works. I tried to Google it and all I get is information regarding Work Bench and phpMyAdmin.
The MySQL server runs as a service (or daemon) on your server - so the folder (or directory) you put it in is set by the system configuration and has nothing to do with your document root for your web site.
In PHP, you will "connect" to the MySQL service using PDO or something similar and then send requests to the MySQL server using PHP commands.
When you are running the MySQL command line interpreter, you can also test those same commands by typing them yourself. This is helpful when you're debugging your PHP program so you can see the data that your program will get yourself in the command line interface.
I hope this helps put you in the right picture.
I tried to Google it and all I get is information regarding Work Bench and myPhpAdmin
this is the first entry on the first page when I google php mysql, it covers everything from installation up to code example.
Very generally:
You need to check with your hosting company if they offer you locally hosted MySQL server access. Using cpanel/phpMyAdmin, or whatever tools they have available for you, you can then login and create multiple databases as you please - each database maybe corresponding to one of your site folders. Once you have created your account and your databases, you can use php commands from your website code to connect to/manipulate whichever database you want.
EDIT: I missed where you said you already have a MySQL localhost setup. Now you need to login to your SQL server and create one or more databases and one or more user accounts for those databases. Create an admin account with all the privileges. Then you can use php in your webpage to connect to a database, using something like this:
$con = mysql_connect("localhost", "your_MySQL_username", "your_MySQL_password") or die ("Unable to connect to MySQL Server " . mysql_error());
if(is_resource($con))
$db = mysql_select_db($MySQL_database, $con) or die( "Unable to select database " . mysql_error());
See the manual for more ways to query the database and handle the results: http://php.net/manual/en/ref.mysql.php

Categories