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


PHP mysql_insert_id函数代码示例

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


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

示例1: _findId

 /** Convert name to id (add Style to database if not exists)
  *
  * @return bool
  */
 protected function _findId()
 {
     global $Database, $Config, $Log;
     // get data from database to compare
     $sql = "SELECT name as name,\n\t\tnameid as nameid,\n\t\tid__module as id__module\n\t    FROM #__modules\n\t    WHERE name = '" . mysql_real_escape_string($this->getInfofile('name')) . "'\n\t\tAND nameid = '" . mysql_real_escape_string($this->getInfofile('nameid')) . "';";
     $result = $Database->doSelect($sql);
     if ($result === false or count($result) > 1) {
         return false;
     }
     // new module?
     if (count($result) == 0) {
         $Log->doLog(3, "Module: Found new module '" . $this->getInfofile('name') . "'");
         // add module to database
         $sql = "INSERT INTO #__modules\n\t\tSET name = '" . mysql_real_escape_string($this->getInfofile('name')) . "',\n\t\t    nameid = '" . mysql_real_escape_string($this->getInfofile('nameid')) . "',\n\t\t    version = '" . mysql_real_escape_string($this->getInfofile('version')) . "',\n\t\t    author = '" . mysql_real_escape_string($this->getInfofile('author')) . "',\n\t\t    link = '" . mysql_real_escape_string($this->getInfofile('link')) . "',\n\t\t    description = '" . mysql_real_escape_string($this->getInfofile('description')) . "'\n\t    ;";
         $result = $Database->doInsert($sql);
         if (!$result) {
             return false;
         }
         // save id
         $this->id = mysql_insert_id();
         // preparse
         $this->_preparse();
         return true;
     }
     // save id
     $this->id = $result[0]['id__module'];
     // update found! -> replace old version
     if ($this->getInfofile('version') > $this->getInfo('version')) {
         $Log->doLog(3, "Module: Update of module '" . $this->getInfofile('name') . "' found.");
         // update database
         $sql = "UPDATE #__modules\n\t\tSET version = '" . mysql_real_escape_string($this->getInfofile('version')) . "',\n\t\t    author = '" . mysql_real_escape_string($this->getInfofile('author')) . "',\n\t\t    link = '" . mysql_real_escape_string($this->getInfofile('link')) . "',\n\t\t    description = '" . mysql_real_escape_string($this->getInfofile('description')) . "',\n\t\t    nameid = '" . mysql_real_escape_string($this->getInfofile('nameid')) . "'\n\t\tWHERE id__module = '" . $this->id . "'\n\t    ;";
         $result_1 = $Database->doUpdate($sql);
         if (!$result_1) {
             return false;
         }
         // backup old version
         ts_BackupHandler::backupModule($Config->get('dir_data') . '/source/modules/_mod' . $this->id, $this->getInfofile('name') . '_' . $this->getInfofile('nameid') . '__version__' . $this->getInfofile('version'));
         // preparse (and replace old version by that)
         $this->_preparse();
         // version is same as saved in database
     } elseif ($this->getInfofile('version') == $this->getInfo('version')) {
         // get correct path
         $path_correct = $this->_getPath(false, false);
         // check, if in correct folder
         if ($this->path != $path_correct) {
             $Log->doLog(3, "Module: Move module '" . $this->getInfofile('name') . "' to correct path.");
             $this->_preparse();
         }
         // old version found! -> delete this one
     } else {
         $Log->doLog(3, "Module: Remove old version of module '" . $this->getInfofile('name') . "'.");
         // backup and delete folder
         ts_BackupHandler::backupModule($this->path);
         ts_FileHandler::deleteFolder($this->path);
         // delete id
         $this->id = 0;
         return false;
     }
     return true;
 }
开发者ID:nfrickler,项目名称:tsunic,代码行数:64,代码来源:ts_Module.class.php

示例2: grabar_venta

 public function grabar_venta($pedido, $cliente, $tipo_documento, $nro_documento, $serie_documento)
 {
     $query = "INSERT INTO ventas(ped_id,cli_id,ven_fecha,ven_estado,ven_nrodoc,tipc_id,ven_seriedoc) VALUES ('{$pedido}','{$cliente}','" . date('y-m-d') . "','0','{$nro_documento}','{$tipo_documento}','{$serie_documento}')";
     $rs = mysql_query($query);
     $_SESSION['venta_codigo'] = mysql_insert_id();
     return $rs;
 }
开发者ID:kailIII,项目名称:Sistema-de-ventas-1.0,代码行数:7,代码来源:ventas_data.php

示例3: save

 function save()
 {
     $rValue = false;
     if ($this->name != "" && $this->project_id != "" && $this->version != "") {
         global $dbh;
         if ($this->file_id == 0) {
             $this->file_id = $this->getFileID($this->name, $this->project_id, $this->version);
         }
         $sql = "INSERT INTO";
         $where = "";
         if ($this->file_id > 0) {
             $sql = "UPDATE";
             $where = " WHERE file_id = " . sqlSanitize($this->file_id, $dbh);
         }
         $Event = new EventLog("files", "file_id", $this->file_id, $sql);
         $sql .= " files \n\t\t\t\t\t\tSET file_id \t= " . sqlSanitize($this->file_id, $dbh) . ",\n\t\t\t\t\t\t\tproject_id\t= " . returnQuotedString(sqlSanitize($this->project_id, $dbh)) . ", \n\t\t\t\t\t\t\tversion\t\t= " . returnQuotedString(sqlSanitize($this->version, $dbh)) . ", \n\t\t\t\t\t\t\tname\t\t= " . returnQuotedString(sqlSanitize($this->name, $dbh)) . ",\n\t\t\t\t\t\t\tplugin_id\t= " . returnQuotedString(sqlSanitize($this->plugin_id, $dbh)) . ",\n\t\t\t\t\t\t\tis_active\t= " . $this->is_active . $where;
         if (mysql_query($sql, $dbh)) {
             if ($this->file_id == 0) {
                 $this->file_id = mysql_insert_id($dbh);
                 $Event->key_value = $this->file_id;
             }
             $rValue = true;
             $Event->add();
         } else {
             echo $sql . "\n";
             $GLOBALS['g_ERRSTRS'][1] = mysql_error();
         }
     } else {
         echo "ERROR: One missing:Name: " . $this->name . "Project: " . $this->project_id . "Version: " . $this->version;
     }
     return $rValue;
 }
开发者ID:Tiger66639,项目名称:server-1,代码行数:32,代码来源:file.class.php

示例4: create

 function create($params, $files)
 {
     self::validate($params);
     $link = self::db_connect();
     $params = self::clear_params($params, $link);
     $table = get_called_class() . 's';
     $val_fields = array_map(function ($f) {
         return "`" . $f . "`";
     }, static::$fields);
     $values = [];
     foreach (static::$fields as $field) {
         array_push($values, '"' . $params[$field] . '"');
     }
     foreach (static::$file_fields as $field) {
         if ($files[$field]['name']) {
             $dir_path = 'uploads/' . get_called_class() . '/';
             mkdir($dir_path, 0777);
             $file_path = $dir_path . $files[$field]['name'];
             move_uploaded_file($files[$field]['tmp_name'], $file_path);
             array_push($val_fields, '`' . $field . '`');
             array_push($values, '"' . $file_path . '"');
         }
     }
     $request_fields = implode(', ', $val_fields);
     $request_values = implode(', ', $values);
     $query = "INSERT INTO .`" . $table . "` (" . $request_fields . ") VALUES (" . $request_values . ")";
     $result = mysql_query($query, $link) or die('MySQL error: ' . mysql_error());
     $id = mysql_insert_id($link);
     mysql_close($link);
     return $id;
 }
开发者ID:KirillDmitrievich,项目名称:php-test-app,代码行数:31,代码来源:dbtable.php

示例5: place_order

function place_order($have_amount_disp, $have_currency, $want_amount_disp, $want_currency)
{
    global $is_logged_in;
    $have_currency = strtoupper($have_currency);
    $want_currency = strtoupper($want_currency);
    curr_supported_check($have_currency);
    curr_supported_check($want_currency);
    // convert for inclusion into database
    $have_amount = numstr_to_internal($have_amount_disp);
    $want_amount = numstr_to_internal($want_amount_disp);
    if ($have_currency == 'BTC') {
        order_worthwhile_check($have_amount, $have_amount_disp, $have_currency, MINIMUM_BTC_AMOUNT);
        order_worthwhile_check($want_amount, $want_amount_disp, $want_currency, MINIMUM_FIAT_AMOUNT);
    } else {
        order_worthwhile_check($have_amount, $have_amount_disp, $have_currency, MINIMUM_FIAT_AMOUNT);
        order_worthwhile_check($want_amount, $want_amount_disp, $want_currency, MINIMUM_BTC_AMOUNT);
    }
    enough_money_check($have_amount, $have_currency);
    do_query("START TRANSACTION");
    // deduct money from their account
    deduct_funds($have_amount, $have_currency);
    // add the money to the order book
    $query = "\n        INSERT INTO orderbook (\n            uid,\n            initial_amount,\n            amount,\n            type,\n            initial_want_amount,\n            want_amount,\n            want_type)\n        VALUES (\n            '{$is_logged_in}',\n            '{$have_amount}',\n            '{$have_amount}',\n            '{$have_currency}',\n            '{$want_amount}',\n            '{$want_amount}',\n            '{$want_currency}');\n    ";
    $result = do_query($query);
    $orderid = mysql_insert_id();
    do_query("COMMIT");
    return $orderid;
}
开发者ID:martinkirov,项目名称:intersango,代码行数:28,代码来源:order_utils.php

示例6: query

 public function query($query = "")
 {
     try {
         $results = array();
         $queryString = trim($query);
         $explodedQuery = explode(' ', $queryString);
         $queryFirstWord = strtoupper(trim($explodedQuery[0]));
         $response = mysql_query($queryString, $this->databaseConnection);
         if ($response) {
             if (is_resource($response)) {
                 while ($row = mysql_fetch_assoc($response)) {
                     $results[] = $row;
                 }
             }
             switch ($queryFirstWord) {
                 case "DELETE":
                 case "UPDATE":
                     return mysql_affected_rows();
                     break;
                 case "INSERT":
                     return mysql_insert_id();
                     break;
                 default:
                     return $results;
                     break;
             }
         } else {
             return mysql_error();
         }
     } catch (Exception $error) {
         echo 'Caught exception: ', $error->getMessage(), "\n";
     }
 }
开发者ID:RunningBear87,项目名称:tools,代码行数:33,代码来源:MySQL_DB.php

示例7: AddInsurance

 public function AddInsurance()
 {
     global $dbObj, $common;
     //header('Content-type: application/json');
     $action = $common->replaceEmpty('action', '');
     $document_name = $common->replaceEmpty('docname', '');
     $document_date = $common->replaceEmpty('docdate', '');
     $document_quick_note = $common->replaceEmpty('docquicknote', '');
     $document_type = $common->replaceEmpty('doctype', '');
     $vechile_id = $common->replaceEmpty('vecid', '');
     $document = $common->replaceEmpty('document', '');
     $email = $common->replaceEmpty('email', '');
     $password = $common->replaceEmpty('password', '');
     if ($action = 'adddocuments') {
         $sql = $dbObj->runQuery("select * from user_reg where email='" . $email . "' AND password ='" . md5($password) . "' ");
         if (mysql_num_rows($sql) > 0) {
             $add_insurance = "insert into document (document_name,document_date,document_quick_note,created_date,document_type,vecid,email,document) \n\t\t\tvalues ('" . $document_name . "','" . $document_date . "','" . $document_quick_note . "',NOW(),'" . $document_type . "','" . $vechile_id . "','" . $email . "','" . $document . "')";
             $dbObj->runQuery($add_insurance);
             $docunentid = mysql_insert_id();
             $result[] = array("docid" => $docunentid, "message" => "Document has been Added.");
             //$result['login-status']= "1";
             //$finalarray[] =  $result;
             echo json_encode(array('result' => $result));
         }
     }
 }
开发者ID:ranrolls,项目名称:php-web-services,代码行数:26,代码来源:AddinsuranceClass.class.php

示例8: dbInsert

function dbInsert($data, $table)
{
    global $fullSql;
    global $db_stats;
    // the following block swaps the parameters if they were given in the wrong order.
    // it allows the method to work for those that would rather it (or expect it to)
    // follow closer with SQL convention:
    // insert into the TABLE this DATA
    if (is_string($data) && is_array($table)) {
        $tmp = $data;
        $data = $table;
        $table = $tmp;
        // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE);
    }
    $sql = 'INSERT INTO `' . $table . '` (`' . implode('`,`', array_keys($data)) . '`)  VALUES (' . implode(',', dbPlaceHolders($data)) . ')';
    $time_start = microtime(true);
    dbBeginTransaction();
    $result = dbQuery($sql, $data);
    if ($result) {
        $id = mysql_insert_id();
        dbCommitTransaction();
        // return $id;
    } else {
        if ($table != 'Contact') {
            trigger_error('QDB - Insert failed.', E_USER_WARNING);
        }
        dbRollbackTransaction();
        // $id = false;
    }
    // logfile($fullSql);
    $time_end = microtime(true);
    $db_stats['insert_sec'] += number_format($time_end - $time_start, 8);
    $db_stats['insert']++;
    return $id;
}
开发者ID:n-st,项目名称:librenms,代码行数:35,代码来源:dbFacile.mysql.php

示例9: giveUserPokemon

function giveUserPokemon($uid, $name, $level, $exp, $move1, $move2, $move3, $move4)
{
    $uid = (int) $uid;
    $level = (int) $level;
    $exp = (int) $exp;
    $name = cleanSql($name);
    $move1 = cleanSql($move1);
    $move2 = cleanSql($move2);
    $move3 = cleanSql($move3);
    $move4 = cleanSql($move4);
    $gender = rand(0, 2);
    mysql_query("\n\t\tINSERT INTO `user_pokemon` (\n\t\t\t`uid`, `name`, `level`, `exp`, `move1`, `move2`, `move3`, `move4`, `gender`\n\t\t) VALUES (\n\t\t\t'{$uid}', '{$name}', '{$level}', '{$exp}', '{$move1}', '{$move2}', '{$move3}', '{$move4}', '{$gender}'\n\t\t)\n\t");
    $pokeId = mysql_insert_id();
    $query = mysql_query("SELECT `poke1`,`poke2`,`poke3`,`poke4`,`poke5`,`poke6` FROM `users` WHERE `id`='{$uid}'");
    if (mysql_num_rows($query) == 1) {
        $pokeIds = mysql_fetch_assoc($query);
        for ($i = 1; $i <= 6; $i++) {
            if ($pokeIds['poke' . $i] == '0') {
                mysql_query("UPDATE `users` SET `poke{$i}`='{$pokeId}' WHERE `id`='{$uid}'");
                break;
            }
        }
    }
    return $pokeId;
}
开发者ID:Yanrs,项目名称:PkmnChan,代码行数:25,代码来源:functions.php

示例10: storeUser

 /**
  * Storing new user
  * returns user details
  */
 public function storeUser($firstname, $lastname, $email, $username, $password)
 {
     //echo "$firstname, $lastname, $email, $username, $password";
     $hash = $this->hashSSHA($password);
     $encrypted_password = $hash["encrypted"];
     // encrypted password
     $salt = $hash["salt"];
     // salt
     $query = "INSERT INTO user(firstname, lastname, email, username, password, salt) VALUES ('{$firstname}', '{$lastname}','{$email}', '{$username}', '{$encrypted_password}', '{$salt}')";
     //echo $query;
     $result = mysql_query($query) or die(mysql_error());
     //print_r($result);
     // check for successful store
     if ($result) {
         // get user details
         $uid = mysql_insert_id();
         // last inserted id
         $result = mysql_query("SELECT * FROM user WHERE id = {$uid}");
         //create Directory for new User with EMAIL
         if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/api/registratedUserhome/' . $email)) {
             mkdir($_SERVER['DOCUMENT_ROOT'] . '/api/registratedUserhome/' . $email, 0777, true);
             //echo "Ordner erfolgreich erstellt";
         }
         // return user details
         return mysql_fetch_array($result);
     } else {
         return false;
     }
 }
开发者ID:HauckA,项目名称:SecureHome,代码行数:33,代码来源:DB_Functions.php

示例11: insertUrl

 public function insertUrl($url)
 {
     $date = date('F d, Y');
     $query = "INSERT INTO url_shortener (long_url, date_created)\n\t\t\t\t\t  VALUES('{$url}', '{$date}');";
     mysql_query($query);
     return mysql_insert_id();
 }
开发者ID:Hepic,项目名称:url-shortener,代码行数:7,代码来源:short_url.php

示例12: addImage

 function addImage($data)
 {
     $sql = 'INSERT into `image` (name) VALUES ("' . $data['name'] . '")';
     if (mysql_query($sql)) {
         return $id = mysql_insert_id();
     }
 }
开发者ID:shiftingmoods,项目名称:GoActiveBackend,代码行数:7,代码来源:simpleImage.php

示例13: addBilling

    function addBilling($Billing){
        global $adb;
		global $table_prefix;
		
		$firstname = addslashes($Billing->firstname);
		$lastname = addslashes($Billing->lastname);
		$address = addslashes($Billing->address);
		$address1 = addslashes($Billing->address1);
		$city = addslashes($Billing->city);
		  
        $query="INSERT INTO ".$table_prefix."_tblBilling SET ".
            "fldBillingClientID='$Billing->client_id',". 			
			"fldBillingLastname='$lastname',". 
			"fldBillingFirstName='$firstname',". 
			"fldBillingEmail='$Billing->email',".			
			"fldBillingAddress='$address',".
			"fldBillingAddress1='$address1',".
			"fldBillingCity='$Billing->city',".
			"fldBillingState='$Billing->state',".
			"fldBillingCountry='$Billing->country',".
			"fldBillingZip='$Billing->zip',".
			"fldBillingPhoneNo='$Billing->phone'";			
			            
        $adb->query($query);
        return mysql_insert_id();
    }
开发者ID:romackdnr,项目名称:dnrpiggyments,代码行数:26,代码来源:Billing.php

示例14: db_insert

function db_insert($table, $hash)
{
    $fields = array_keys($hash);
    $sql = "INSERT INTO `{$table}` (`" . implode('`,`', $fields) . "`) VALUES ('" . implode("','", $hash) . "')";
    $result = db_query($sql);
    return mysql_insert_id();
}
开发者ID:Digitalbil,项目名称:Choose,代码行数:7,代码来源:db.php

示例15: Create

 /**
  * Create a new user group
  * @access  public
  * @param   title
  *          description
  * @return  user id, if successful
  *          false and add error into global var $msg, if unsuccessful
  * @author  Cindy Qi Li
  */
 public function Create($title, $description)
 {
     global $addslashes, $msg;
     $missing_fields = array();
     /* email check */
     $title = $addslashes(trim($title));
     /* login name check */
     if ($title == '') {
         $missing_fields[] = _AT('title');
     }
     if ($missing_fields) {
         $missing_fields = implode(', ', $missing_fields);
         $msg->addError(array('EMPTY_FIELDS', $missing_fields));
     }
     if (!$msg->containsErrors()) {
         /* insert into the db */
         $sql = "INSERT INTO " . TABLE_PREFIX . "user_groups\n\t\t\t              (title,\n\t\t\t               description,\n\t\t\t               create_date\n\t\t\t               )\n\t\t\t       VALUES ('" . $title . "',\n\t\t\t               '" . $description . "',\n\t\t\t               now()\n\t\t\t              )";
         if (!$this->execute($sql)) {
             $msg->addError('DB_NOT_UPDATED');
             return false;
         } else {
             return mysql_insert_id();
         }
     } else {
         return false;
     }
 }
开发者ID:harriswong,项目名称:AContent,代码行数:36,代码来源:UserGroupsDAO.class.php


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