Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. int _value = 0;
  2.  
  3. connectionClass() = default;
  4.  
  5.  
  6. virtual ~connectionClass() = default;
  7.  
  8. Php::Value getValue() const
  9. {
  10. return _value;
  11. }
  12.  
  13.  
  14. void setValue(const Php::Value &value)
  15. {
  16. // overwrite property
  17. _value = value;
  18.  
  19. // sanity check: the value should never exceed 100
  20. if (_value > 100) _value = 100;
  21. }
  22.  
  23.  
  24. Php::Value getDouble() const
  25. {
  26. return _value * 2;
  27. }
  28.  
  29.  
  30. Php::Value connectionDB()
  31. {
  32. try{
  33. connection C("dbname=testing user=mmubeen password=y7u8i9o0
  34. hostaddr=127.0.0.1 port=5432");
  35. if (C.is_open()) {
  36. cout << "Opened database successfully: " << C.dbname() << endl;
  37. } else {
  38. cout << "Can't open database" << endl;}
  39. return 1;
  40.  
  41. C.disconnect ();
  42. }catch (const std::exception &e){
  43. cerr << e.what() << std::endl;
  44. return 1;
  45. }
  46.  
  47. cout << "Code running " << endl;
  48. }
  49.  
  50. PHPCPP_EXPORT void *get_module() {
  51. // create static extension object
  52. static Php::Extension myExtension("skeleton", "1.0");
  53.  
  54. Php::Class<connectionClass> example("connectionClass");
  55.  
  56.  
  57. example.property("value", &connectionClass::getValue, &connectionClass::setValue);
  58.  
  59.  
  60. example.property("double", &connectionClass::getDouble);
  61. example.property("connection", &connectionClass::connectionDB);
  62. //example.method<&Example::connectionDB>("connectionDB");
  63. // add the class to the extension
  64. myExtension.add(std::move(example));
  65.  
  66. // return the extension
  67. return myExtension;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement