How to determine the mysql database connection address? -PHP Chinese website Q&A-How to determine the mysql database connection address? -PHP Chinese website Q&A
<?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) { die('Could not connect : ' . mysql_error()); }
// some code
?>
This is the first type and is suitable for all versions. .
##<?php/* Connect to a MySQL server Connect to the database server*/$link = mysqli_connect( 'localhost', /* The host to connect to Connect to MySQL Address*/
'jian', /* The user to connect as MySQL username*/ '123456', /* The password to use MySQL password*/ 'jian'); / * The default database to query connection database name*/if (!$link) { printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error()); exit; }else echo 'The database is connected! ';/* Close the connection Close the connection */mysqli_close($link);?>
This is the second way of writing. Only available after php4.5. object method.
How to determine the mysql database connection address? -PHP Chinese website Q&A-How to determine the mysql database connection address? -PHP Chinese website Q&A
How to determine the mysql database connection address? -PHP Chinese website Q&A-How to determine the mysql database connection address? -PHP Chinese website Q&A
Let’s take a look and learn.
Either use mysqli PDO
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect : ' . mysql_error());
}
// some code
?>
This is the first type and is suitable for all versions. .
##<?php/* Connect to a MySQL server Connect to the database server*/$link = mysqli_connect( 'localhost', /* The host to connect to Connect to MySQL Address*/'jian', /* The user to connect as MySQL username*/
This is the second way of writing. Only available after php4.5. object method.'123456', /* The password to use MySQL password*/
'jian'); / * The default database to query connection database name*/if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}else
echo 'The database is connected! ';/* Close the connection Close the connection */mysqli_close($link);?>
How to determine the mysql database connection address? -PHP Chinese website Q&A-How to determine the mysql database connection address? -PHP Chinese website Q&A
Please watch and learn.
jdbc:mysql://[数据库服务器IP地址]/[数据库名] 例如:局域网内一mysql服务器 IP地址为172.10.1.100,数据库名为test 链接地址为 jdbc:mysql://172.10.1.100/test 如果是本机,IP地址可以直接写为localhost