some easy questions about c++

1. is it possible to link the c++ files with databases like oracle,MySql?
(coding the file to access the databases)

2. can we put the compiled files on websites?
Google.com is build in C and C++ and their search engine is running on that. how is that possible?

Dani AI

Generated

Short answers for (and clarification of points raised by , and ):

Yes — C++ programs can connect to databases and they can be used to produce web pages. Database access is done with a client library/driver (vendor libraries or a DB-agnostic layer) that your C++ code calls; the web server runs the compiled program on the server and sends that program’s output back to the browser. (dev.mysql.com)

Concrete options and quick checklist for databases

  • MySQL: use the official Connector/C++ or the C client library and link at build time.
  • Oracle: use OCCI (or OCI/Instant Client) for native C++ bindings.
  • Portability: use ODBC (unixODBC on Linux) to write one data-access layer that works with many back ends.
    Steps: pick a driver, install the client library on the machine you’ll run on, include headers and link the library when compiling, and test the connection locally before deploying. (unixodbc.org)

How to make a compiled C++ program produce a webpage

  • Typical models: CGI (executes a program per request), FastCGI (keeps processes running for performance), or use a C++ web framework that embeds an HTTP server. On the server you do not “browse” the .exe — the web server executes it and forwards its stdout as the HTTP response. For production you’ll usually prefer FastCGI or a framework rather than raw CGI. (httpd.apache.org)

Minimal example (concept only — compile for the server OS/arch):

#include <iostream>

int main() {
    std::cout << "Content-Type: text/html\r\n\r\n";
    std::cout << "<html><body><h1>Hello from C++ CGI</h1></body></html>\n";
    return 0;
}

Practical tips: compile on the same OS/architecture as the server, set executable permissions, put the binary where the server is configured to run CGI/FastCGI, check server error logs if nothing appears, and verify that the DB client libraries are installed on the server. If the hosting environment is shared or restricted, you may not be allowed to run arbitrary executables — in that case use a supported FastCGI/setup or a hosted language/framework.

Recommended Answers

All 9 Replies

some easy questions about c++

1. is it possible to link the c++ files with databases like oracle,MySql?
(coding the file to access the databases)

2. can we put the compiled files on websites?
Google.com is build in C and C++ and their search engine is running on that. how is that possible?

1. Yes. You will need an Application Programming Interface (API). I believe it comes standand with mySQL and the same is probably true for Oracle.

2. The compiled file will generate (build) the webpage on the server which is then displayed on the browser.

but the compiled file has .exe extension

how can we make that generate the webpage?

iam a bit confused cause .exe cant be browsed by browser and i dotn know how to generate the webpage on server.....

any special software?

any help/hint is appreciated

I suppose that generating a webpage means just putting stuff into a html file, just like any other file. You put HTML code in it.

If you want to write CGI programs in C or C++, and want to know how it works, read this tutorial:

This is not how Google does things, though. What do you think web servers like Apache are written in? C and C++. Google has its own software that is a specialized web server.

You should not be using C or C++ to dynamically serve your web documents, not because you can't, or for technical reasons, but because it's really much easier to use a language like PHP that's more suited for the purpose.

I think it would help if you understood a bit about how HTTP works. One computer sends a request to another, looking something like

GET /search?q=foo+bar HTTP/1.1
Host: www.google.com

Then the other computer replies with some information followed by the webpage. The computer that sends the request has no idea what the server is doing on what languages are used to write the web server, and it doesn't care.

thanks for information very much. i will try it

PHP

Did I just actually recommend using PHP? Oh god no! Anything but PHP. That was just an example of what /other/ people use :-)

Member Avatar for Member #46692

Did I just actually recommend using PHP? Oh god no! Anything but PHP. That was just an example of what /other/ people use :-)

Ack, I just recently skipped down to the shops and got myself a php/mysql/apache all in one book. Was that a mistake? :cry:

You're posting in the C++ forum. What do you expect? :)

Member Avatar for Member #46692

You're posting in the C++ forum. What do you expect? :)

Oh thanx dani, I was beginning to worry I wasted my money. Yay. :mrgreen:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.