略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: maxdb_connect

2024-12-22

maxdb_connect

maxdb::__construct

(PECL maxdb >= 1.0)

maxdb_connect -- maxdb::__constructOpen a new connection to the MaxDB server

说明

过程化风格

maxdb_connect ([ string $host [, string $username [, string $passwd [, string $dbname [, int $port = 0 [, string $socket ]]]]]] ) : resource

面向对象风格

maxdb::__construct ([ string $host [, string $username [, string $passwd [, string $dbname [, int $port = 0 [, string $socket ]]]]]] )

The maxdb_connect() function attempts to open a connection to the MaxDB Server running on host which can be either a host name or an IP address. Passing the string "localhost" to this parameter, the local host is assumed. If successful, the maxdb_connect() will return an resource representing the connection to the database 或者在失败时返回 FALSE.

The username and password parameters specify the username and password under which to connect to the MaxDB server. If the password is not provided (the NULL value is passed), the MaxDB server will attempt to authenticate the user against the maxdb.default_pw in php.ini.

The dbname parameter if provided will specify the default database to be used when performing queries. If not provied, the entry maxdb.default_db in php.ini is used.

The port and socket parameters are ignored for the MaxDB server.

返回值

Returns a resource which represents the connection to a MaxDB Server or FALSE if the connection failed.

范例

Example #1 面向对象风格

<?php
$maxdb 
= new maxdb("localhost""MONA""RED""DEMODB");

/* check connection */
if (maxdb_connect_errno()) {
   
printf("Connect failed: %s\n"maxdb_connect_error());
   exit();
}

printf("Host information: %s\n"$maxdb->host_info);

/* close connection */
$maxdb->close();
?>

Example #2 过程化风格

<?php
$link 
maxdb_connect("localhost""MONA""RED""DEMODB");

/* check connection */
if (!$link) {
   
printf("Connect failed: %s\n"maxdb_connect_error());
   exit();
}

printf("Host information: %s\n"maxdb_get_host_info($link));

/* close connection */
maxdb_close($link);
?>

以上例程的输出类似于:

Host information: localhost
add a note add a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.maxdb-connect.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3