Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int _value = 0;
- connectionClass() = default;
- virtual ~connectionClass() = default;
- Php::Value getValue() const
- {
- return _value;
- }
- void setValue(const Php::Value &value)
- {
- // overwrite property
- _value = value;
- // sanity check: the value should never exceed 100
- if (_value > 100) _value = 100;
- }
- Php::Value getDouble() const
- {
- return _value * 2;
- }
- Php::Value connectionDB()
- {
- try{
- connection C("dbname=testing user=mmubeen password=y7u8i9o0
- hostaddr=127.0.0.1 port=5432");
- if (C.is_open()) {
- cout << "Opened database successfully: " << C.dbname() << endl;
- } else {
- cout << "Can't open database" << endl;}
- return 1;
- C.disconnect ();
- }catch (const std::exception &e){
- cerr << e.what() << std::endl;
- return 1;
- }
- cout << "Code running " << endl;
- }
- PHPCPP_EXPORT void *get_module() {
- // create static extension object
- static Php::Extension myExtension("skeleton", "1.0");
- Php::Class<connectionClass> example("connectionClass");
- example.property("value", &connectionClass::getValue, &connectionClass::setValue);
- example.property("double", &connectionClass::getDouble);
- example.property("connection", &connectionClass::connectionDB);
- //example.method<&Example::connectionDB>("connectionDB");
- // add the class to the extension
- myExtension.add(std::move(example));
- // return the extension
- return myExtension;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement