search

Home  >  Q&A  >  body text

Common methods for connecting to MYSQL database with PHP

Configuring a Xiaoniao cloud server and deploying a PHP environment, what are the common methods for connecting to a MYSQL database?

想无想无1199 days ago1110

reply all(3)I'll reply

  • Z

    Z2021-09-18 14:32:07

    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);?>

    reply
    1
  • yntdx

    yntdx2021-09-08 09:49:10

    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

    reply
    0
  • autoload

    autoload2021-09-08 09:24:41

    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.

    reply
    0
  • Cancelreply