I'm trying to start working with mysqli and OOP, but it isn't working out that well. I can't get my mysqli methods working starting with a simple connect_errno method.
Can anyone help me out?
The connection to the database seems to be made, since I tried it with an other Password (access denied). With the correct Password I got the following error:
Fatal error: Call to undefined method mysqli::connect_errno() in C:\xampp2\htdocs\badeendenrace\db\db.php on line 7
<?php
$dbhost='localhost';
$dbuser='Tjerk';
$dbdata='badeendenrace';
$dbpw='123test';
$db = new mysqli($dbhost,$dbuser,$dbpw,$dbdata);
if ($db->connect_errno())
{
echo "Connection failed: ".$db->connect_error()."\n";
exit();
}
?>
I'm using the latest version of Xampp (Reïnstalled it today) with PHP version 5.5.6
As Rocket Hazmat said, connect_errno isn't a function. The same to connect_error. So just take away the round brackets after both in your code.
if ($db->connect_errno)
{
echo "Connection failed: ".$db->connect_error."\n";
exit();
}
It seems that you have confused the object oriented function with the procedural. You mention OOP so I assume you want the OOP version.
$db = new mysqli($dbhost,$dbuser,$dbpw,$dbdata);
if ($db->connect_errno) //no parenthesis
{
echo "Connection failed: ".$db->connect_error."\n"; //no parenthesis
exit();
}
For procedural
$db = new mysqli($dbhost,$dbuser,$dbpw,$dbdata);
if (!$db)
{
echo "Connection failed: ".mysqli_connect_error(); //parenthesis
exit();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With