企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
MySQL连接 ``` <?php $dbhost = 'localhost'; // mysql服务器主机地址 $dbuser = 'root'; // mysql用户名 $dbpass = '123456'; // mysql用户名密码 $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysqli_error()); } echo '数据库连接成功!'; mysqli_close($conn); ``` 访问指定数据库: ``` <?php $dbhost = '127.0.0.1';      // mysql server ip $dbuser = 'root'; // mysql username $dbpass = '123456'; // mysql password $database = 'test'; // mysql database $port = 3306; // mysql port $conn = mysqli_connect($dbhost, $dbuser, $dbpass, $database, $port); if (!$conn) { die('Failed to connect to MySQL: ' . mysqli\_error($conn)); } echo 'Successfully connected to MySQL'; $db = mysqli_select_db($conn, $database); if (!$db) { die('Failed to access the database: ' . mysqli\_error($conn)); } mysqli\_close($conn); echo 'Successfully accessed the database'; ```