The error message you are getting indicates that the function `mysqli_connect` does not exist in the specified database. \n\nIn 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:\n\nmysql\nDELIMITER //\n\nCREATE PROCEDURE connect_to_remote_db()\nBEGIN\n DECLARE conn_success INT DEFAULT 0;\n DECLARE conn_error VARCHAR(255) DEFAULT '';\n\n DECLARE remote_conn VARCHAR(255) DEFAULT '127.0.0.1';\n DECLARE remote_user VARCHAR(255) DEFAULT 'root';\n DECLARE remote_password VARCHAR(255) DEFAULT '123456';\n DECLARE remote_db VARCHAR(255) DEFAULT 'your_remote_db_name';\n\n DECLARE remote_db_conn INT DEFAULT NULL;\n\n SET remote_db_conn = mysqli_init();\n\n IF remote_db_conn IS NULL THEN\n SET conn_error = 'Failed to initialize remote database connection.';\n ELSE\n SET conn_success = mysqli_real_connect(remote_db_conn, remote_conn, remote_user, remote_password, remote_db);\n\n IF conn_success = 0 THEN\n SET conn_error = 'Failed to connect to remote database.';\n ELSE\n -- Do whatever you want to do with the remote database connection\n -- Example: SELECT * FROM remote_table;\n END IF;\n\n -- Close the remote database connection\n CALL mysqli_close(remote_db_conn);\n END IF;\n\n IF conn_error != '' THEN\n -- Handle the error\n SELECT conn_error AS 'Error';\n ELSE\n -- Success message\n SELECT 'Connected to remote database successfully.' AS 'Message';\n END IF;\nEND //\n\nDELIMITER ;\n\n\nYou 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.

MySQL存储过程连接远程数据库:mysqli_connect 报错解决方法

原文地址: https://www.cveoy.top/t/topic/ptaK 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录