I have a problem executing mysqli from magento. I need it to query an external db and retrive tracking information.

I added this code to a php plugin file:

$conn = new mysqli($db_server, $db_user, $db_pass, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);

$sql = "SELECT `label_url` FROM tracking WHERE `tracking_carrier` = 'BRT' AND `tracking_number` = '$trackingNumber';";
$result = $conn->query($sql); ```

but when loading the page i got a 500 erro.

I then opened the php log and found

```PHP Fatal error:  Uncaught Error: Class 'Plugin\Order\mysqli```

It looks like i cannot use **mysqli**

Is there any other way to query an external db with a mysql query?

1 Answer 1


I solved just adding a backslash in front of the msqli

$conn = new \mysqli($db_server, $db_user, $db_pass, $db_name);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.