0

I am trying to connect to mysql via php using this line

  @ $db = new mysqli_connect('localhost', 'bookorama', 'bookorama123', 'books');
 if (mysqli_connect_errno()) {
 echo 'Error: Could not connect to database.  Please try again later.';
 exit;
 }

I am not getting any response, no error message, nothing. I even added an echo'hi'; after the first line of code and it doesn't show up. When I added echo'hi'; before the first line hi prints out.

Any tips?

3 Answers 3

2

Get rid of the new instead do:

 $db = mysqli_connect(...

or use new to create a mysqli object

 $db = new mysqli(...

In the first case $db is assigned the return value of a function. The mysqli_connect function passes back the object created internal to the function. In the second case $db is being created through the new keyword as the result of the "new mysqli(..." expression.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried the first one and I am now getting Fatal error: Call to undefined function mysqli_connect()
@Aaron Do you have mysqli installed? See here php.net/manual/en/mysqli.installation.php
0

First of all, remove the @ before function calls. @ is to suppress any errors from coming up.

Second, remove the new keyword. That's for instantiating a new class, not calling a function.

Comments

0
$db = @mysqli_connect('localhost', 'bookorama', 'bookorama123', 'books');

mysqli_connect is not an object it is function

EDIT:

remove @, make sure your error_reporting( E_ALL );

$db = mysqli_connect('localhost', 'bookorama', 'bookorama123', 'books');

"Call to undefined function mysqli_connect()" - do you have mysqli module on ? - Yes in php.ini file.

1 Comment

Is this the modle? extension=php_mysqli.dll [PHP_OCI8]

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.