trouble logging into mysql using php
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 get开发者_开发知识库ting 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?
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.
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.
$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.
精彩评论