如何解决 "Warning: mysqli_real_connect() expects parameter 1 to be mysqli, string given" 错误?
How to solve "Warning: mysqli_real_connect() expects parameter 1 to be mysqli, string given" error?
当我使用下面这段代码时,它工作得很好。
$db_conn = mysqli_connect(HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE);
但是当我想使用下面的代码创建交互式 MySQL 连接时。
$db_conn = mysqli_real_connect(HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE,$flags=MYSQLI_CLIENT_INTERACTIVE);
我遇到了这个错误。
Warning: mysqli_real_connect() expects parameter 1 to be mysqli, string given in <source_file> on line 74
如何正确使用 mysqli_real_connect()
?
来自the manual:
mysqli_real_connect() needs a valid object which has to be created by function mysqli_init().
$mysqli = mysqli_init();
$db_conn = mysqli_real_connect($mysqli, HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE, 3306, null, MYSQLI_CLIENT_INTERACTIVE);
面向对象风格:-
<?php
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db');
mysqli_real_connect()
函数不同于 mysqli_connect()
mysqli_real_connect()
需要一个必须由函数 mysqli_init()
.
创建的有效对象
试试这个..
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', 'db_user', 'db_pass', 'db_name');
其中:
db_name代表数据库名
db_pass代表数据库密码
当我使用下面这段代码时,它工作得很好。
$db_conn = mysqli_connect(HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE);
但是当我想使用下面的代码创建交互式 MySQL 连接时。
$db_conn = mysqli_real_connect(HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE,$flags=MYSQLI_CLIENT_INTERACTIVE);
我遇到了这个错误。
Warning: mysqli_real_connect() expects parameter 1 to be mysqli, string given in <source_file> on line 74
如何正确使用 mysqli_real_connect()
?
来自the manual:
mysqli_real_connect() needs a valid object which has to be created by function mysqli_init().
$mysqli = mysqli_init();
$db_conn = mysqli_real_connect($mysqli, HOSTNAME, DBUSERNAME, DBPASSWORD,DATABASE, 3306, null, MYSQLI_CLIENT_INTERACTIVE);
面向对象风格:-
<?php
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', 'my_user', 'my_password', 'my_db');
mysqli_real_connect()
函数不同于 mysqli_connect()
mysqli_real_connect()
需要一个必须由函数 mysqli_init()
.
试试这个..
$mysqli = mysqli_init();
$mysqli->real_connect('localhost', 'db_user', 'db_pass', 'db_name');
其中: db_name代表数据库名 db_pass代表数据库密码