PHP in win down to write in C + + EXE example

Source: Internet
Author: User
Tags php code sql error

First use vc2008 to write an EXE program, the code is as follows:
#include "stdafx.h"
#include <string>

The code is as follows Copy Code

#include <iostream>
#include <sstream>
#include ". /sqlite3_lib/sqlite3.h "
/**
Demonstrates the process of PHP calling C + + for data manipulation.
**/

#pragma comment (lib, "...). /sqlite3_lib/sqlite3.lib ")
using namespace Std;
static int _sql_callback (void * notused, int argc, char * * argv, char * * szcolname)
{
int i;
for (i=0 i < argc; i++)
{
printf ("%s =%sn", Szcolname[i], argv[i] = = 0? "NUL": Argv[i]);
}
return 0;
}

int main (int argc, char * argv[])
{
String Name= "";
int age=0;
String birthday= "1985-05-16";
if (argc>3)
{
cout<< "Number of arguments is" <<argc<<endl;
NAME=ARGV[1];
Age=atoi (argv[2]);
BIRTHDAY=ARGV[3];

} else{
cout<< "did not get enough command-line arguments, please enter" <<endl;
cout<< "Please enter your name, age, Birthday" in turn <<endl;
cin>>name;
cin>>age;
cin>>birthday;
}
StringStream Strstream;
Strstream <<age;
string s = Strstream.str ();
String isql= "insert into users values (' +name+", "+s+", "+birthday+"); ";
cout<<isql<<endl;
const char * sSQL1 = "CREATE TABLE users" (userid varchar () PRIMARY KEY, age int, birthday datetime); ";
const char * sSQL2 = "SELECT * from users;";
Sqlite3 * db = 0;
char * perrmsg = 0;
int ret = 0;

Connecting to a database
ret = Sqlite3_open ("./db.db", &db);
if (ret!= SQLITE_OK)
{
fprintf (stderr, "Cannot Open database:%s", sqlite3_errmsg (db));
return (1);
}

printf ("Database connection succeeded!n");
Execute the Build table SQL
Sqlite3_exec (db, sSQL1, 0, 0, &perrmsg);
if (ret!= SQLITE_OK)
{
fprintf (stderr, "SQL Error:%SN", perrmsg);
Sqlite3_free (PERRMSG);
}

Execute INSERT Record SQL
Sqlite3_exec (DB, Isql.c_str (), 0, 0, &perrmsg);
Querying data tables
Sqlite3_exec (db, sSQL2, _sql_callback, 0, &perrmsg);
Close Database
Sqlite3_close (DB);
db = 0;
return 0;
}

Compile to EXE file, and then PHP code:
<?php

The code is as follows Copy Code
echo System (' E:/temp/sqlitedemo.exe LALA2 24 1988-02-12 ');

    Note that
1. Use the system function to invoke the executable function, and after the win for the file name space plus parameters, the parameters are separated by spaces, not commas.
2. The command line to pass the parameters to the EXE, in the executable file is argv get, rather than scanf,cin and other inputs, because in this case, can not get input from PHP.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.