mysql mysql存储过程连接查询远程数据库 mysqli_connect 远程地址 1270013306 root 123456 mysqli_connect 报错 FUNCTION lvmhuatmysqli_connect does not exist
The error message you are getting indicates that the function mysqli_connect does not exist in the specified database.
In MySQL, the function to connect to a remote database using MySQLi extension is mysqli_init followed by mysqli_real_connect. Here is an example of how you can connect to a remote MySQL database using a stored procedure:
DELIMITER //
CREATE PROCEDURE connect_to_remote_db()
BEGIN
DECLARE conn_success INT DEFAULT 0;
DECLARE conn_error VARCHAR(255) DEFAULT '';
DECLARE remote_conn VARCHAR(255) DEFAULT '127.0.0.1';
DECLARE remote_user VARCHAR(255) DEFAULT 'root';
DECLARE remote_password VARCHAR(255) DEFAULT '123456';
DECLARE remote_db VARCHAR(255) DEFAULT 'your_remote_db_name';
DECLARE remote_db_conn INT DEFAULT NULL;
SET remote_db_conn = mysqli_init();
IF remote_db_conn IS NULL THEN
SET conn_error = 'Failed to initialize remote database connection.';
ELSE
SET conn_success = mysqli_real_connect(remote_db_conn, remote_conn, remote_user, remote_password, remote_db);
IF conn_success = 0 THEN
SET conn_error = 'Failed to connect to remote database.';
ELSE
-- Do whatever you want to do with the remote database connection
-- Example: SELECT * FROM remote_table;
END IF;
-- Close the remote database connection
CALL mysqli_close(remote_db_conn);
END IF;
IF conn_error != '' THEN
-- Handle the error
SELECT conn_error AS 'Error';
ELSE
-- Success message
SELECT 'Connected to remote database successfully.' AS 'Message';
END IF;
END //
DELIMITER ;
You can call the stored procedure connect_to_remote_db to connect to the remote MySQL database. Modify the variables remote_conn, remote_user, remote_password, and remote_db with the appropriate values for your remote database
原文地址: https://www.cveoy.top/t/topic/hJ5F 著作权归作者所有。请勿转载和采集!