简体   繁体   English

为什么不能连接到mysql

[英]why can't connect to the mysql

one: i using this code to connect mysql databse which on a shared host. 一:我使用此代码连接共享主机上的mysql数据库。

  <?php

 mysql_connect("localhost", "user", "123") or die(mysql_error());

 echo "Connected to MySQL<br />";

  ?>;

the user and password are created by the cpanel.which are the database's user and password. 用户和密码由cpanel创建。这是数据库的用户和密码。

two: i use this line mysql -hlocalhost -uuser -p123 in my window operation system MS-DOS window. 二:我在我的窗口操作系统MS-DOS窗口中使用mysql -hlocalhost -uuser -p123这行。 but it still can't connect the mysql. 但它仍然无法连接mysql。 why? 为什么?

I think you need to declare a variable. 我认为您需要声明一个变量。 ie $link = mysql_connect("...") ... or you might want to specify which db you want to connect to, the db name. $link = mysql_connect("...") ...或您可能想指定要连接到的数据库名称。

http://php.net/manual/en/function.mysql-connect.php http://php.net/manual/zh/function.mysql-connect.php

mysqli_connect("host_parameter", "user_parameter", "password_parameter, "database_parameter"); mysqli_connect(“ host_parameter”,“ user_parameter”,“ password_parameter,” database_parameter“);

$link= mysqli_connect("localhost","root","root_password","my_database");

if(empty($link)){
   die("Error:" . mysqli_error());
}

if it's your first time ( mysql user_parameter = root and password = "") 如果是您第一次(mysql user_parameter = root和password =“”)

HOPE IT HELP U 希望有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM