MySQLi - Construct

语法

mysqli mysqli_connect  ( ... )

定义和用法

它用于打开与 MySQL 服务器的新连接。

示例

试试下面的例子 −

<?php
   $servername = "localhost:3306";
   $username = "root";
   $password = "";
   $dbname = "TUTORIALS";
   $conn = new mysqli($servername, $username, $password, $dbname);

   if ($conn->connect_error) {
      die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
   } 
   echo 'Success... ' . mysqli_get_host_info($conn) . "
";
   mysqli_autocommit($conn,FALSE);
   mysqli_query($conn,"INSERT INTO tutorials_auto (id,name)
   
   VALUES (10,'sai')");
   mysqli_commit($conn);
   
   mysqli_close($conn);
?>

上述代码的示例输出应该是这样的 −

Success... localhost:3306 via TCP/IP

mysqli_useful_functions.html