In fact, there are several common ways to deploy a PHP environment using Xiaoniao Cloud Server and connect to a MYSQL database. Here is the most common one: $mysql_server="localhost";$mysql_username="database username";$ mysql_password="database password";$mysql_database="database name";//Establish a database link//Select a database//Execute MySQL statements//Extract data
The cloud server simulation environment is no different from the local one. First check whether mysql is successfully installed. You can connect using mysqli or pdo.
You can refer to the following
<?php$con = mysql_connect("localhost","root","password");$select_db = mysql_select_db('test');if (!$select_db) { die("could not connect to the db:\n" . mysql_error());}//Query code $sql = "select * from db_table";$res = mysql_query($sql);if (!$res) { die("could get the res:\n" . mysql_error());}while ($row = mysql_fetch_assoc($res)) { print_r($row);}//Query code//Close the database connection mysql_close($ con);?>
In fact, there are several common ways to deploy a PHP environment using Xiaoniao Cloud Server and connect to a MYSQL database. Here is the most common one: $mysql_server="localhost";$mysql_username="database username";$ mysql_password="database password";$mysql_database="database name";//Establish a database link//Select a database//Execute MySQL statements//Extract data
The cloud server simulation environment is no different from the local one. First check whether mysql is successfully installed. You can connect using mysqli or pdo.