0

I am trying to create a custom connection to my database through Magento 2.1.8.

I am trying to use the mysqli library.

The method I am using worked in Magento 1.9 but will not work in my current version.

$conn = new mysqli($servername, $username, $password, $database);

When i use this code, i am receiving an error:

Uncaught Error: Class 'VendorName\Forum\Controller\Post\mysqli' not found in /domains/mywebsite.com/http/app/code/VendorName/Forum/Controller/Post/postMessage.php:28

How do i import the mysqli class to create this object?

Thanks.

0

You should write a below code with backslash

$conn = new \mysqli($servername, $username, $password, $database);

1
  • excellent, this worked for me Thank you. Why does adding the backslash make this work? – user61783 Jan 16 '18 at 13:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy