如何连接到mysql数据库

时间:2014-11-27 17:42:49

标签: php mysql

如何使用以下信息编写连接字符串以连接到mysql数据库: 使用php连接字符串

  1. 数据库详细信息:

4 个答案:

答案 0 :(得分:0)

基本的,不安全的。

<?php
mysql_connect(localhost, ##YOUR USERNAME##, ##YOUR PASSWORD##);
mysql_select_db('##YOUR DATABASE NAME##');


$result = mysql_query("SELECT * FROM emails");
?>

并更新了mysqli http://www.sanwebe.com/2013/03/basic-php-mysqli-usage

答案 1 :(得分:0)

使用mysqlimysqli connection是这样的:

$host = "localhost";
$database = "wlfmedic_ptest1";
$username = "wlfmedic_ptest1";
$password = 'Prog@te$t104';

$connection = mysqli_connect($host, $username, $password, $database);
if(mysqli_connect_errno()){ //To show error if fails to connect
    die(mysqli_connect_error());
}

答案 2 :(得分:0)

<?php

  $db_hostName="localhost";

  $databaseName= "wlfmedic_ptest1";

  $db_userName= "wlfmedic_ptest1";

  $db_password= "Prog@te$t104";

  $con=mysql_connect($db_hostName,$db_userName,$db_password);
    if(!$con){
      die ("Could Not successfully with DataBase".mysql_error());
    }else{
      echo "Connect connect with succssfully .";
    }

    $db=mysql_select_db($db_databaseName,$con);
    if(!$db)
    {
      echo "Can notConnect with Bd Social";
    }
    else
    {
      echo "Conncet With Bd Social";
    }

?>

try this .. 

答案 3 :(得分:-1)

<?PHP

$user_name = "root";
$password = "";
$database = "addressbook";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);

$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

print "Database Found ";
mysql_close($db_handle);

}
else {

print "Database NOT Found ";

}

?>
  

also you can refer this link