5 antwortet
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// some code
?>
这个是第一种,适合所有版本。.
<?php/* Connect to a MySQL server 连接数据库服务器 */$link = mysqli_connect( 'localhost', /* The host to connect to 连接MySQL地址 */
'jian', /* The user to connect as 连接MySQL用户名 */
'123456', /* The password to use 连接MySQL密码 */
'jian'); /* The default database to query 连接数据库名称*/if (!$link) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}else
echo '数据库连接上了!';/* Close the connection 关闭连接*/mysqli_close($link);?>
这是第二种写法。php4.5后才可以。对象法。
jdbc:mysql://[数据库服务器IP地址]/[数据库名] 例如:局域网内一mysql服务器 IP地址为172.10.1.100,数据库名为test 链接地址为 jdbc:mysql://172.10.1.100/test 如果是本机,IP地址可以直接写为localhost
Hot-Tools-Tags
Hot Questions
Hot Tools
Sammlung der Laufzeitbibliothek vc9-vc14 (32+64 Bit) (Link unten)
Laden Sie die Sammlung der Laufzeitbibliotheken herunter, die für die Installation von phpStudy erforderlich sind
VC9 32-Bit
VC9 32-Bit-Laufzeitbibliothek für die integrierte Installationsumgebung von phpstudy
Vollversion der PHP-Programmierer-Toolbox
Programmer Toolbox v1.0 PHP Integrierte Umgebung
VC11 32-Bit
VC11 32-Bit-Laufzeitbibliothek für die integrierte Installationsumgebung von phpstudy
SublimeText3 chinesische Version
Chinesische Version, sehr einfach zu bedienen





