当前位置: 首页>>代码示例>>PHP>>正文


PHP mysql_connect函数代码示例

本文整理汇总了PHP中mysql_connect函数的典型用法代码示例。如果您正苦于以下问题:PHP mysql_connect函数的具体用法?PHP mysql_connect怎么用?PHP mysql_connect使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mysql_connect函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: connect_db

function connect_db()
{
    global $myserv;
    $myserv = mysql_connect("localhost", MYSQL_USER, MYSQL_PASSWD);
    mysql_select_db(MYSQL_DATABASE);
    mysql_set_charset('utf8');
}
开发者ID:elsayhsoft,项目名称:fossil-grader,代码行数:7,代码来源:db.php

示例2: getTangentText

function getTangentText($type, $keyword)
{
    global $dbHost, $dbUser, $dbPassword, $dbName;
    $link = @mysql_connect($dbHost, $dbUser, $dbPassword);
    if (!$link) {
        die("Cannot connect : " . mysql_error());
    }
    if (!@mysql_select_db($dbName, $link)) {
        die("Cannot find database : " . mysql_error());
    }
    $result = mysql_query("SELECT sr_keywords, sr_text FROM soRandom WHERE sr_type = '" . $type . "' ORDER BY sr_ID ASC;", $link);
    $tempCounter = 0;
    while ($row = mysql_fetch_assoc($result)) {
        $pKey = "/" . $keyword . "/";
        $pos = preg_match($pKey, $row['sr_keywords']);
        //echo $pos . " is pos<br>";
        //echo $keyword;
        //echo " is keyword and this is the search return: " . $row['keywords'];
        if ($pos != 0) {
            $text[$tempCounter] = stripslashes($row["sr_text"]);
            $tempCounter++;
        }
    }
    mysql_close($link);
    //$text=htmlentities($text);
    return $text;
}
开发者ID:ui-libraries,项目名称:TIRW,代码行数:27,代码来源:includes.php

示例3: db

 function db($dbhost, $dbuser, $dbpw, $dbname = '', $dbcharset = 'utf8', $pconnect = 0)
 {
     if ($pconnect) {
         if (!($this->mlink = @mysql_pconnect($dbhost, $dbuser, $dbpw))) {
             $this->halt('Can not connect to MySQL');
         }
     } else {
         if (!($this->mlink = @mysql_connect($dbhost, $dbuser, $dbpw))) {
             $this->halt('Can not connect to MySQL');
         }
     }
     if ($this->version() > '4.1') {
         if ('utf-8' == strtolower($dbcharset)) {
             $dbcharset = 'utf8';
         }
         if ($dbcharset) {
             mysql_query("SET character_set_connection={$dbcharset}, character_set_results={$dbcharset}, character_set_client=binary", $this->mlink);
         }
         if ($this->version() > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->mlink);
         }
     }
     if ($dbname) {
         mysql_select_db($dbname, $this->mlink);
     }
 }
开发者ID:eappl,项目名称:prototype,代码行数:26,代码来源:db.class.php

示例4: Global_Init

function Global_Init()
{
    //session_start();
    Load_Configs();
    if (!strnatcasecmp(trim($GLOBALS['db']['type']), "LB")) {
        require_once 'inc/dbmodule_LB.php';
    }
    if (!strnatcasecmp(trim($GLOBALS['db']['type']), "GD")) {
        require_once 'inc/dbmodule_GD.php';
    }
    //echo "GLOBALS: <BR>"; print_r($GLOBALS['db']); echo "<BR>";
    $source_db_ok = SQL_DB_OK("source");
    if ($source_db_ok['error'] === false) {
        $GLOBALS['db']['s_resource'] = @mysql_connect($GLOBALS['db']['s_host'], $GLOBALS['db']['s_user'], $GLOBALS['db']['s_pass']) or die($_SERVER["SCRIPT_FILENAME"] . "Could not connect to Source MySQL Server. : " . mysql_error());
        @mysql_selectdb($GLOBALS['db']['s_base']) or die("Could not connect to Source database [" . $GLOBALS['db']['s_base'] . "] : " . mysql_error());
        $GLOBALS['db']['x_resource'] = @mysql_connect($GLOBALS['db']['x_host'], $GLOBALS['db']['x_user'], $GLOBALS['db']['x_pass']) or die($_SERVER["SCRIPT_FILENAME"] . "Could not connect to X-Ray  MySQL Server. : " . mysql_error());
        @mysql_selectdb($GLOBALS['db']['x_base']) or die("Could not connect to X-Ray database [" . $GLOBALS['db']['x_base'] . "] : " . mysql_error());
        $GLOBALS['db']['s_link'] = mysqli_connect($GLOBALS['db']['s_host'], $GLOBALS['db']['s_user'], $GLOBALS['db']['s_pass'], $GLOBALS['db']['s_base']) or die($_SERVER["SCRIPT_FILENAME"] . "Could not connect to Source MySQL Server (multilink). : " . mysqli_error($GLOBALS['db']['s_link']));
        mysqli_select_db($GLOBALS['db']['s_link'], $GLOBALS['db']['s_base']) or die("Could not connect to Source database (multilink) [" . $GLOBALS['db']['s_base'] . "] : " . mysqli_error($GLOBALS['db']['s_link']));
        $GLOBALS['db']['x_link'] = mysqli_connect($GLOBALS['db']['x_host'], $GLOBALS['db']['x_user'], $GLOBALS['db']['x_pass'], $GLOBALS['db']['x_base']) or die($_SERVER["SCRIPT_FILENAME"] . "Could not connect to X-Ray MySQL Server (multilink). : " . mysqli_error($GLOBALS['db']['x_link']));
        mysqli_select_db($GLOBALS['db']['x_link'], $GLOBALS['db']['x_base']) or die("Could not connect to X-Ray database (multilink) [" . $GLOBALS['db']['x_base'] . "] : " . mysqli_error($GLOBALS['db']['x_link']));
    } else {
        $config_error .= $source_db_ok['message'] . "<BR>";
    }
    //	array_key_exists('form', $_POST) && $_POST['form']!="" ? $_GET = $_POST : NULL;
    //	array_key_exists('force', $_GET) && $_GET['force']!="" ? $_POST = $_GET : NULL;
    if (count($_GET) > 0) {
        $_POST = $_GET;
    }
    //	if($_POST['form']!=""){$_GET = $_POST;}
    //	if($_GET['force']!=""){$_POST = $_GET;}
    if (!FixOutput_Bool($GLOBALS['config_settings']['settings']['first_setup'], true, false, true)) {
        $GLOBALS['worlds'] = Get_Worlds_Enabled();
    }
}
开发者ID:babbottscott,项目名称:X-Ray-Detective,代码行数:35,代码来源:core_xdetector.php

示例5: validate

 private function validate()
 {
     if (!defined('DB_HOSTNAME')) {
         $this->error['warning'] = 'Host required!';
     }
     if (!defined('DB_USERNAME')) {
         $this->error['warning'] = 'User required!';
     }
     if (!defined('DB_DATABASE')) {
         $this->error['warning'] = 'Database Name required!';
     }
     if (!($connection = @mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD))) {
         $this->error['warning'] = 'Error: Could not connect to the database please make sure the database server, username and password is correct in the config.php file!';
     } else {
         if (!@mysql_select_db(DB_DATABASE, $connection)) {
             $this->error['warning'] = 'Error: Database "' . DB_DATABASE . '" does not exist!';
         }
         mysql_close($connection);
     }
     if (!$this->error) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:nareshrajaram,项目名称:referralcartdev,代码行数:25,代码来源:upgrade.php

示例6: connect

 /**
 +----------------------------------------------------------
 * 连接数据库方法
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 public function connect($config = '', $linkNum = 0)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // 处理不带端口号的socket连接情况
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         if ($this->pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum])) {
             throw_exception(mysql_error());
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         if ($dbVersion >= "4.1") {
             //使用UTF8存取数据库 需要mysql 4.1.0以上支持
             mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         }
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // 标记连接成功
         $this->connected = true;
         // 注销数据库连接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:omusico,项目名称:AndyCMS,代码行数:43,代码来源:DbMysql.class.php

示例7: __connect

 /**
  * DB Connect
  * this method is private
  * @param array $connection connection's value is db_hostname, db_port, db_database, db_userid, db_password
  * @return resource
  */
 function __connect($connection)
 {
     // Ignore if no DB information exists
     if (strpos($connection["db_hostname"], ':') === false && $connection["db_port"]) {
         $connection["db_hostname"] .= ':' . $connection["db_port"];
     }
     // Attempt to connect
     $result = @mysql_connect($connection["db_hostname"], $connection["db_userid"], $connection["db_password"]);
     if (!$result) {
         exit('XE cannot connect to DB.');
     }
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     // Error appears if the version is lower than 4.1
     if (version_compare(mysql_get_server_info($result), '4.1', '<')) {
         $this->setError(-1, 'XE cannot be installed under the version of mysql 4.1. Current mysql version is ' . mysql_get_server_info());
         return;
     }
     // select db
     @mysql_select_db($connection["db_database"], $result);
     if (mysql_error()) {
         $this->setError(mysql_errno(), mysql_error());
         return;
     }
     return $result;
 }
开发者ID:perzona420,项目名称:xe-core,代码行数:34,代码来源:DBMysql.class.php

示例8: db_connect

function db_connect()
{
    // połączenie z mysql
    mysql_connect(DBHOST, DBUSER, DBPASS) or die('<h2>ERROR</h2> MySQL Server is not responding');
    // wybór bazy danych
    mysql_select_db(DBNAME) or die('<h2>ERROR</h2> Cannot connect to specified database');
}
开发者ID:polekopru,项目名称:AplikacjeInternetowe,代码行数:7,代码来源:config.php

示例9: connect

 /**
  * 连接数据库方法
  * @access public
  * @throws ThinkExecption
  */
 public function connect($config = '', $linkNum = 0, $force = false)
 {
     if (!isset($this->linkID[$linkNum])) {
         if (empty($config)) {
             $config = $this->config;
         }
         // 处理不带端口号的socket连接情况
         $host = $config['hostname'] . ($config['hostport'] ? ":{$config['hostport']}" : '');
         // 是否长连接
         $pconnect = !empty($config['params']['persist']) ? $config['params']['persist'] : $this->pconnect;
         if ($pconnect) {
             $this->linkID[$linkNum] = mysql_pconnect($host, $config['username'], $config['password'], CLIENT_MULTI_RESULTS);
         } else {
             $this->linkID[$linkNum] = mysql_connect($host, $config['username'], $config['password'], true, CLIENT_MULTI_RESULTS);
         }
         if (!$this->linkID[$linkNum] || !empty($config['database']) && !mysql_select_db($config['database'], $this->linkID[$linkNum]) || C('SPARE_DB_DEBUG')) {
             $errStr = mysql_error();
             $errno = mysql_errno();
             if ($errno == 13047 || C('SPARE_DB_DEBUG')) {
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('mysql超额被禁用,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR);
                 }
                 //[sae]启动备用数据库
                 if (C('SPARE_DB_HOST')) {
                     $this->linkID[$linkNum] = mysql_connect(C('SPARE_DB_HOST') . (C('SPARE_DB_PORT') ? ':' . C('SPARE_DB_PORT') : ''), C('SPARE_DB_USER'), C('SPARE_DB_PWD'), true, CLIENT_MULTI_RESULTS);
                     if (!$this->linkID[$linkNum]) {
                         throw_exception('备用数据库连接失败');
                     }
                     mysql_select_db(C('SPARE_DB_NAME'), $this->linkID[$linkNum]);
                     //标记使用备用数据库状态
                     $this->is_spare = true;
                 } else {
                     throw_exception($errStr);
                 }
             } else {
                 //[sae] 短信预警
                 if (C('SMS_ALERT_ON')) {
                     Sms::send('数据库连接时出错,请在SAE日志中心查看详情', $errStr, Sms::MYSQL_ERROR);
                 }
                 throw_exception($errStr);
             }
         }
         $dbVersion = mysql_get_server_info($this->linkID[$linkNum]);
         if ($dbVersion >= '4.1') {
             //使用UTF8存取数据库 需要mysql 4.1.0以上支持
             mysql_query("SET NAMES '" . C('DB_CHARSET') . "'", $this->linkID[$linkNum]);
         }
         //设置 sql_model
         if ($dbVersion > '5.0.1') {
             mysql_query("SET sql_mode=''", $this->linkID[$linkNum]);
         }
         // 标记连接成功
         $this->connected = true;
         // 注销数据库连接配置信息
         if (1 != C('DB_DEPLOY_TYPE')) {
             unset($this->config);
         }
     }
     return $this->linkID[$linkNum];
 }
开发者ID:ysking,项目名称:commlib,代码行数:65,代码来源:DbMysql.class.php

示例10: connecttodb

function connecttodb($servername,$dbname,$dbuser,$dbpassword)
{
    $link=mysql_connect ("$servername","$dbuser","$dbpassword",TRUE);
    if(!$link){die("Could not connect to MySQL");}
    mysql_select_db("$dbname",$link) or die ("could not open db".mysql_error());
    return $link;
}
开发者ID:ravinderphp,项目名称:revitalise,代码行数:7,代码来源:update.php

示例11: check_connection

function check_connection($user, $pass, $host)
{
    if (!($connection = @mysql_connect("{$host}", "{$user}", "{$pass}"))) {
        return false;
    }
    return $connection;
}
开发者ID:vinothtimes,项目名称:phpdoc,代码行数:7,代码来源:main.php

示例12: HackingLog

function HackingLog()
{
    echo "You're not allowed to use this program! This attempted violation has been logged and your IP address was captured.";
    Warehouse('footer');
    if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
    } else {
        $ip = $_SERVER['REMOTE_ADDR'];
    }
    if ($openSISNotifyAddress) {
        mail($openSISNotifyAddress, 'HACKING ATTEMPT', "INSERT INTO HACKING_LOG (HOST_NAME,IP_ADDRESS,LOGIN_DATE,VERSION,PHP_SELF,DOCUMENT_ROOT,SCRIPT_NAME,MODNAME,USERNAME) values('{$_SERVER['SERVER_NAME']}','{$ip}','" . date('Y-m-d') . "','{$openSISVersion}','{$_SERVER['PHP_SELF']}','{$_SERVER['DOCUMENT_ROOT']}','{$_SERVER['SCRIPT_NAME']}','{$_REQUEST['modname']}','" . User('USERNAME') . "')");
    }
    /*if($openSISNotifyAddress)
    		mail($openSISNotifyAddress,'HACKING ATTEMPT',"INSERT INTO HACKING_LOG (HOST_NAME,IP_ADDRESS,LOGIN_DATE,VERSION,PHP_SELF,DOCUMENT_ROOT,SCRIPT_NAME,MODNAME,USERNAME) values('$_SERVER[SERVER_NAME]','$_SERVER[REMOTE_ADDR]','".date('Y-m-d')."','$openSISVersion','$_SERVER[PHP_SELF]','$_SERVER[DOCUMENT_ROOT]','$_SERVER[SCRIPT_NAME]','$_REQUEST[modname]','".User('USERNAME')."')");*/
    if (false && function_exists('mysql_query')) {
        if ($_SERVER['HTTP_X_FORWARDED_FOR']) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        $link = @mysql_connect('os4ed.com', 'openSIS_log', 'openSIS_log');
        @mysql_select_db('openSIS_log');
        @mysql_query("INSERT INTO HACKING_LOG (HOST_NAME,IP_ADDRESS,LOGIN_DATE,VERSION,PHP_SELF,DOCUMENT_ROOT,SCRIPT_NAME,MODNAME,USERNAME) values('{$_SERVER['SERVER_NAME']}','{$ip}','" . date('Y-m-d') . "','{$openSISVersion}','{$_SERVER['PHP_SELF']}','{$_SERVER['DOCUMENT_ROOT']}','{$_SERVER['SCRIPT_NAME']}','{$_REQUEST['modname']}','" . User('USERNAME') . "')");
        @mysql_close($link);
        /*$link = @mysql_connect('os4ed.com','openSIS_log','openSIS_log');
        		@mysql_select_db('openSIS_log');
        		@mysql_query("INSERT INTO HACKING_LOG (HOST_NAME,IP_ADDRESS,LOGIN_DATE,VERSION,PHP_SELF,DOCUMENT_ROOT,SCRIPT_NAME,MODNAME,USERNAME) values('$_SERVER[SERVER_NAME]','$_SERVER[REMOTE_ADDR]','".date('Y-m-d')."','$openSISVersion','$_SERVER[PHP_SELF]','$_SERVER[DOCUMENT_ROOT]','$_SERVER[SCRIPT_NAME]','$_REQUEST[modname]','".User('USERNAME')."')");
        		@mysql_close($link);*/
    }
}
开发者ID:26746647,项目名称:Belize-openSIS,代码行数:30,代码来源:HackingLog.php

示例13: Open

function Open($dbType, $connectType = "c", $connect, $username = "", $password = "", $dbName)
{
    switch ($dbType) {
        case "mssql":
            if ($connectType == "c") {
                $idCon = mssql_connect($connect, $username, $password);
            } else {
                $idCon = mssql_pconnect($connect, $username, $password);
            }
            mssql_select_db($dbName);
            break;
        case "mysql":
            if ($connectType == "c") {
                $idCon = @mysql_connect($connect, $username, $password);
            } else {
                $idCon = @mysql_pconnect($connect, $username, $password);
            }
            $idCon1 = mysql_select_db($dbName, $idCon);
            break;
        case "pg":
            if ($connectType == "c") {
                $idCon = pg_connect($connect . " user=" . $username . " password=" . $password . " dbname=" . $dbName);
            } else {
                $idCon = pg_pconnect($connect . " user=" . $username . " password=" . $password . " dbname=" . $dbName);
            }
            break;
        default:
            $idCon = 0;
            break;
    }
    return $idCon;
}
开发者ID:laiello,项目名称:ebpls,代码行数:32,代码来源:multidbconnection.php

示例14: connect

 function connect()
 {
     require_once 'db_config.php';
     $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
     $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
     return $con;
 }
开发者ID:niesuch,项目名称:cosmetic-ingredients,代码行数:7,代码来源:db_connect.php

示例15: dbConnection

 private function dbConnection()
 {
     // Stabilisce connessione al DB
     $this->connectionResource = @mysql_connect($this->DB_HOST, $this->DB_USER, $this->DB_PASS) or conf::showerror();
     $dbSelect = @mysql_select_db($this->DB_NAME, $this->connectionResource) or conf::showerror();
     mysql_query("set names utf8") or conf::showerror();
 }
开发者ID:seph89,项目名称:AmmProject,代码行数:7,代码来源:db.php


注:本文中的mysql_connect函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。