function mySqlUpit($upit, $tip) { $konekcija = mysqli_connect("localhost", "root", "", "0007cinevision"); $konekcija->set_charset("utf8"); if (mysqli_connect_errno()) { printf("Konekcija nije uspela: %s\n", mysqli_connect_error()); exit; } $rezultat = mysqli_query($konekcija, $upit); if (!$rezultat) { printf("Greska: %s\n", mysqli_error($konekcija)); exit; } if ($tip == 0) { return 0; } if ($tip == 1) { $rez = mysqli_fetch_array($rezultat, MYSQLI_NUM); $konekcija->close(); } else { if ($tip == 2) { $rez = array(); $i = 0; while (($red = mysqli_fetch_array($rezultat)) != NULL) { $rez[$i++] = $red; } } } if (!empty($rez)) { return $rez; } return -1; }
function writeLog($Redirected_URL) { // Add logging to MySQL database $mySQL_username = ""; $mySQL_password = ""; $mySQL_database = ""; // Connect to database $mysqli = new mysqli('localhost', $mySQL_username, $mySQL_password, $mySQL_database); /* check connection */ if (!mysqli_connect_errno()) { /* create a prepared statement */ if ($stmt = $mysqli->prepare("INSERT INTO `stats`\t(`Datetime`,\t`UA`,\t`IP`,\t`Languages`,\t`Domain`,\t`Path`,\t`Destination`) \n\t\t\t\t\t\t\t\t\tVALUES \t(?,\t\t\t\t?,\t\t?,\t\t?,\t\t\t\t \t?,\t\t\t\t?,\t\t\t?)")) { $stmt->bind_param('sssssss', $datetime, $ua, $ip, $languages, $domain, $path, $destination); $datetime = date("Y-m-d H:i:s"); $ua = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER["REMOTE_ADDR"]; $languages = $_SERVER['HTTP_ACCEPT_LANGUAGE']; $domain = $_SERVER['SERVER_NAME']; $path = stripslashes($_GET['title']); $destination = $Redirected_URL; /* execute prepared statement */ $stmt->execute(); /* close statement and connection */ $stmt->close(); // Write a log file entry for each visitor $myFile = "log.txt"; $fh = fopen($myFile, 'a+'); // Tab separated. Date/Time User Agent IP Address Language Server requested Page requested $stringData = $datetime . "\t" . $ua . "\t" . $ip . "\t" . $languages . "\t" . $domain . "\t" . $path . "\t" . $destination . "\n"; fwrite($fh, $stringData); fclose($fh); } } }
public function dbconnect() { mysqli_connect($this->dbhost, $this->dbuser, $this->dbpass, $this->dbdata); if (mysqli_connect_errno()) { return "Failed to connect to MySQL: " . mysqli_connect_error(); } }
/** +---------------------------------------------------------- * 连接数据库方法 +---------------------------------------------------------- * @access public +---------------------------------------------------------- * @throws ThinkExecption +---------------------------------------------------------- */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport']); if (mysqli_connect_errno()) { throw_exception(mysqli_connect_error()); } $dbVersion = $this->linkID[$linkNum]->server_version; if ($dbVersion >= "4.1") { // 设置数据库编码 需要mysql 4.1.0以上支持 $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'"); } //设置 sql_model if ($dbVersion > '5.0.1') { $this->linkID[$linkNum]->query("SET sql_mode=''"); } // 标记连接成功 $this->connected = true; //注销数据库安全信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
function Populate() { //mysql connection $con = mysqli_connect("eu-cdbr-azure-west-a.cloudapp.net", "b8592f1b44ff9a", "fecb2128", "TeamProject"); if (mysqli_connect_errno()) { $result = "f"; } else { //query $query = "SELECT Name,Email FROM Subscriber"; $result = mysqli_query($con, $query); //initialize arrays $i = 0; $subnames = array(); $submails = array(); //loop through the database populating while ($sub = mysqli_fetch_assoc($result)) { $subnames[$i] = $sub['Name']; $submails[$i] = $sub['Email']; $i++; } //close conection and return mysqli_close($con); return array($subnames, $submails); } }
function updateDatabase($tableName, $columnName, $newInput) { $dbHost = "localhost"; // Host name $dbUsername = "******"; // Mysql username $dbPassword = "******"; // Mysql password $dbName = "manager"; // Database name // $tbl_name="customers"; // Table name // Connect to server and select databse. $dbCon = new mysqli("{$dbHost}", "{$dbUsername}", "{$dbPassword}", "{$dbName}"); if (mysqli_connect_errno($dbCon)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $columnName = mysqli_real_escape_string($columnName); $newInput = mysqli_real_escape_string($newInput); $query = "SELECT * FROM {$tableName} WHERE {$columnName} like '%" . "{$newInput}" . "%'"; // UPDATE {$taableName} set {$columnName} = '{$newpassword}' WHERE cust_num = '{$customerNumber}'"; // DEBUG // echo $query . "<br>"; $result = $dbCon->query($query); return $result; }
/** * 连接数据库方法 * @access public * @throws ThinkExecption */ public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $this->linkID[$linkNum] = new \mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport'] ? intval($config['hostport']) : 3306); if (mysqli_connect_errno()) { E(mysqli_connect_error()); } $dbVersion = $this->linkID[$linkNum]->server_version; // 设置数据库编码 $this->linkID[$linkNum]->query("SET NAMES '" . $config['charset'] . "'"); //设置 sql_model if ($dbVersion > '5.0.1') { $this->linkID[$linkNum]->query("SET sql_mode=''"); } // 标记连接成功 $this->connected = true; //注销数据库安全信息 if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
function initDBConnection($test) { if (!$this->db) { if ($test) { echo "\nTrying DB Connection to " . $this->dbcData['DB_HOST'] . "..."; } $this->db = new mysqli($this->dbcData['DB_HOST'], $this->dbcData['DB_USER'], $this->dbcData['DB_PASS'], $this->dbcData['DB_NAME']); /* verificar conexión */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } //To query with ñ and tildes /* cambiar el conjunto de caracteres a utf8 */ if (!$this->db->set_charset("utf8")) { printf("Error cargando el conjunto de caracteres utf8: %s\n", $this->db->error); exit; } else { //printf("Conjunto de caracteres actual: %s\n", $this->db->character_set_name()); } if ($test) { echo "\nConnected!!"; } } }
private function __construct($connect) { if (empty($connect)) { if ($GLOBALS["i"]["dev"]) { $host = "localhost"; $user = "******"; $pass = "******"; $db = "bijoux"; } else { $host = "localhost"; $user = "******"; $pass = "******"; $db = "nickand5_bijoux"; } } else { $host = $connect["host"]; $user = $connect["user"]; $pass = $connect["pass"]; $db = $connect["db"]; } //Connect to db $this->db = mysqli_connect($host, $user, $pass, $db); if (mysqli_connect_error()) { die('Connect Error (' . mysqli_connect_errno() . ') ' . mysqli_connect_error()); } }
public function __construct() { $this->con = mysqli_connect("localhost", "root", "123456", "passgen"); if (mysqli_connect_errno()) { die("Failed to connect to MySQL: " . mysqli_connect_error()); } }
public function open_db_connection() { $this->connection = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); if (mysqli_connect_errno()) { die("connection to database failed: " . mysqli_error()); } }
public function __construct($host, $user, $pwd, $dbname) { $this->db = new mysqli($host, $user, $pwd, $dbname); if (mysqli_connect_errno()) { throw new Exception("Can't connect to mysql..." . mysqli_connect_errno() . ': ' . mysqli_error()); } }
function UpdatePWD($id, $new_pwd) { global $MYSQL_DB_NAME; global $MYSQL_USER_ID; global $MYSQL_USER_PWD; global $LOGON_SESSION_TTL; $mysqli = new mysqli("localhost", $MYSQL_USER_ID, $MYSQL_USER_PWD, $MYSQL_DB_NAME); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $mysqli->query('SET NAMES utf8'); $stmt = $mysqli->prepare("UPDATE `student_roster` SET `pwd`=?, `pwd_update_time`=? WHERE `id`=? ;"); if (!$stmt) { echo "<h1>prepare statement failed !<h1>"; return false; } $stmt->bind_param("sis", $new_pwd, time(), $id); if ($stmt->execute() == FALSE) { echo "<h1>update password failed !<h1>"; $stmt->close(); return false; } // echo ("<h1>affected ". $stmt->affected_rows." rows !<h1>"); $stmt->close(); return true; }
function get_fork_data($job) { global $mysqli; $fork_encrypt_key = md5('huls0fjhslsshskslgjbtqcwijnbxhl2391'); $fork_raw_data = $job->workload(); $fork_metadata = json_decode(AESDecryptCtr(base64_decode($fork_raw_data), $fork_encrypt_key, 256), true); $fork_key = $fork_metadata['fork_key']; $token = $fork_metadata['token']; $inikoo_account_code = $fork_metadata['code']; if (!ctype_alnum($inikoo_account_code)) { print "cant fint account code\n"; return false; } include "gearman/conf/dns.{$inikoo_account_code}.php"; $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $mysqli->query("SET NAMES 'utf8'"); date_default_timezone_set('GMT'); $mysqli->query("SET time_zone='+0:00'"); $sql = sprintf("select `Fork Process Data` from `Fork Dimension` where `Fork Key`=%d and `Fork Token`=%s", $fork_key, prepare_mysql($token)); $res = $mysqli->query($sql); if ($row = $res->fetch_assoc()) { $fork_data = json_decode($row['Fork Process Data'], true); return array('fork_key' => $fork_key, 'inikoo_account_code' => $inikoo_account_code, 'fork_data' => $fork_data); } else { print "fork data not found"; return false; } }
/** * Creates a real connection to the database with multi-query capability. * * @return void * @throws Zend_Db_Adapter_Mysqli_Exception */ protected function _connect() { if ($this->_connection) { return; } if (!extension_loaded('mysqli')) { throw new Zend_Db_Adapter_Exception('mysqli extension is not installed'); } // Suppress connection warnings here. // Throw an exception instead. @($conn = new mysqli()); if (false === $conn || mysqli_connect_errno()) { throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_errno()); } $conn->init(); $conn->options(MYSQLI_OPT_LOCAL_INFILE, true); #$conn->options(MYSQLI_CLIENT_MULTI_QUERIES, true); $port = !empty($this->_config['port']) ? $this->_config['port'] : null; $socket = !empty($this->_config['unix_socket']) ? $this->_config['unix_socket'] : null; // socket specified in host config if (strpos($this->_config['host'], '/') !== false) { $socket = $this->_config['host']; $this->_config['host'] = null; } elseif (strpos($this->_config['host'], ':') !== false) { list($this->_config['host'], $port) = explode(':', $this->_config['host']); } #echo "<pre>".print_r($this->_config,1)."</pre>"; die; @$conn->real_connect($this->_config['host'], $this->_config['username'], $this->_config['password'], $this->_config['dbname'], $port, $socket); if (mysqli_connect_errno()) { throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); } $this->_connection = $conn; /** @link http://bugs.mysql.com/bug.php?id=18551 */ $this->_connection->query("SET SQL_MODE=''"); }
function con_sql($sqlip, $sqlid, $sqlpass) { @($con = new mysqli($sqlip, $sqlid, $sqlpass)); if (mysqli_connect_errno()) { die(mysqli_connect_error()); } }
function __construct() { $this->connection = mysqli_connect($this->host, $this->user, $this->pass, $this->name); if (mysqli_connect_errno($this->connection)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } }
public function connect() { /** if ($this->conn == "pconn") { //永久链接 $this->conn = mysql_pconnect($this->db_host, $this->db_user, $this->db_pwd); } else { //即时链接 $this->conn = mysql_connect($this->db_host, $this->db_user, $this->db_pwd); } if (!mysql_select_db($this->db_database, $this->conn)) { if ($this->show_error) { $this->show_error("数据库不可用:", $this->db_database); } } mysql_query("SET NAMES $this->coding"); **/ if ($this->conn == "pconn") { //永久链接 $this->conn = mysql_pconnect($this->db_host, $this->db_user, $this->db_pwd); } else { //即时链接 $this->conn = mysqli_connect($this->db_host, $this->db_user, $this->db_pwd, $this->db_database); } if (mysqli_connect_errno($this->conn)) { $this->show_error("数据库不可用:", $this->db_database); } mysqli_query($this->conn, "SET NAMES {$this->coding}"); }
public function open_connection() { $this->connection = mysqli_connect('localhost', 'root', '', 'projectbrowser'); if (mysqli_connect_errno()) { die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")"); } }
public function dologin() { include 'core/config.php'; $username = $_POST['username']; $password = $_POST['password']; $dbconnect = new mysqli($sql_host, $sql_user, $sql_password, $sql_db); if (mysqli_connect_errno()) { $this->returnerror("Database error"); } // $query = "SELECT * FROM rob_admins WHERE username="******"AND password="******"SELECT id,username, password FROM rob_admins WHERE username=%s AND password=%s", $this->GetSQLValueString($dbconnect, $username, "text"), $this->GetSQLValueString($dbconnect, $password, "text")); $result = $dbconnect->query($query) or die($dbconnect->error . __LINE__ && $this->returnerror("SQL Error")); header('HTTP/1.1 200 Success'); header('Content-Type: text/xml; charset=UTF-8'); echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; echo "<logindata>\n"; if ($result->num_rows == 1) { $row = $result->fetch_assoc(); $this->setsession(stripslashes($row['id'])); echo "<result>login successfull</result>"; echo "<user>admin</user>"; echo "<target></target>"; } else { echo "<error>NO RESULTS</error>\n"; } echo "</logindata>\n"; return; }
function insertDatabaseFunc($username, $password, $queryType, $entity) { require_once 'queryDatabaseHelper.php'; if (validUsernameAndPassword($username, $password)) { $link = mysqli_connect("localhost", "Tommy", "pickles", "Model"); if (strcmp($queryType, 'Unsubs') == 0) { $query = 'DELETE FROM `subscription` WHERE `username`=\'' . $username . '\' AND `orgnumber`=\'' . $entity . '\''; } elseif (strcmp($queryType, 'RSVP') == 0) { $query = 'INSERT IGNORE INTO `rsvp`(`username`, `eventnumber`) VALUES (\'' . $username . '\',' . $entity . ')'; } elseif (strcmp($queryType, 'Subs') == 0) { $query = 'INSERT INTO `subscription`(`username`, `orgnumber`) VALUES (\'' . $username . '\',\'' . $entity . '\')'; } elseif (strcmp($queryType, 'AndroidDevice') == 0) { $query = 'INSERT IGNORE INTO `androiddevice`(`username`, `device_id`) VALUES (\'' . $username . '\',\'' . $entity . '\')'; } if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } if (mysqli_query($link, $query)) { echo 'true'; } else { echo 'false'; } mysqli_close($link); } else { echo 'false'; } }
public function __construct() { $this->con = new mysqli(__HOST__, __USER__, __PASS__, __BASE__); if (mysqli_connect_errno()) { die("DB connection failed:" . mysqli_connect_error()); } }
function validarLogin($login, $pass) { $con = mysqli_connect("*********", "**********", "**********", "************"); #Se comprueba la conexion if (mysqli_connect_errno()) { echo 'Error de conexion: ' . mysqli_connect_error(); exit; } #Se quitan posibles caracteres especiales [NUL (ASCII 0), \n, \r, \, ', ", y Control-Z] (sql injection) $login = mysqli_real_escape_string($con, $login); $pass = mysqli_real_escape_string($con, $pass); #Se comprueban login y pass hasheada $usuario = mysqli_query($con, "SELECT login, pwd FROM Usuario WHERE login = '******'"); #Se comprueba que se han devuelto resultados if (!$usuario) { echo 'Error en la consulta: ' . mysqli_error($con); exit; } #Se coge el resultado $result = mysqli_fetch_row($usuario); #Si coincide, se devuelve la lista de bichos de ese usuario if ($result[0] == $login && $result[1] == $pass) { return true; } else { return false; } }
function Conexion() { $this->conex = new mysqli("localhost", "root", "", "base_conocimiento"); if (mysqli_connect_errno()) { die("Error al conectar"); } }
function makeDb() { // THIS SHOULD ONLY BE USED IN DEV ENVIRONMENT!!!! // NEEDS TO BE CHANGED WHEN USED TO UPDATE THE SERVER!! $con = new mysqli("localhost", "root", "", "nhvbsr"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //Call our function to get the assoc array.... $statements = setupSQL(); //I added this crappy noob workaround because I'm lazy and don't have time //to do it the right way... // The script was failing because it was trying to add foreign keys //before the reference table existed // so now we make all the tables, then go back and make them again with // all their relative foreign keys... Like I said its a terrible way. foreach ($statements as $queries) { //okay loop through... each value is a sql query so execute it... foreach ($queries as $key => $val) { $res = $con->query($val); // prep the statement for security.... if ($stmt = $con->prepare($val)) { $stmt->execute(); } //if it was no good print the error.... if (!$res) { printf("<br /> Error at Key: {$key}: %s\n", $con->error); } else { echo "<br /> The table '{$key}' was successfully created! <br />"; } } } }
function cometchatDBConnect() { global $dbh; $port = DB_PORT; if (empty($port)) { $port = '3306'; } $dbserver = explode(':', DB_SERVER); if (!empty($dbserver[1])) { $port = $dbserver[1]; } $db_server = $dbserver[0]; $dbh = mysqli_connect($db_server, DB_USERNAME, DB_PASSWORD, DB_NAME, $port); if (mysqli_connect_errno($dbh)) { $dbh = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME, $port, '/tmp/mysql5.sock'); } if (mysqli_connect_errno($dbh)) { echo "<h3>Unable to connect to database due to following error(s). Please check details in configuration file.</h3>"; if (!defined('DEV_MODE') || defined('DEV_MODE') && DEV_MODE != '1') { ini_set('display_errors', 'On'); echo mysqli_connect_error($dbh); ini_set('display_errors', 'Off'); } header('HTTP/1.1 503 Service Temporarily Unavailable'); header('Status: 503 Service Temporarily Unavailable'); header('Retry-After: 10'); /* 10 seconds */ exit; } mysqli_select_db($dbh, DB_NAME); mysqli_query($dbh, "SET NAMES utf8"); mysqli_query($dbh, "SET CHARACTER SET utf8"); mysqli_query($dbh, "SET COLLATION_CONNECTION = 'utf8_general_ci'"); }
public static function _init_mysql($config = array()) { if (empty($config)) { // 记住不要把原来有的配置信息给强制换成$GLOBALS['config']['db'],否则换数据库会有问题 self::$config = empty(self::$config) ? $GLOBALS['config']['db'] : self::$config; } else { self::$config = $config; } if (!self::$conn) { self::$conn = @mysqli_connect(self::$config['host'], self::$config['user'], self::$config['pass'], self::$config['name'], self::$config['port']); if (mysqli_connect_errno()) { self::$conn_fail++; $errmsg = 'Mysql Connect failed[' . self::$conn_fail . ']: ' . mysqli_connect_error(); echo util::colorize(date("H:i:s") . " {$errmsg}\n\n", 'fail'); log::add($errmsg, "Error"); // 连接失败5次,中断进程 if (self::$conn_fail >= 5) { exit(250); } self::_init_mysql($config); } else { // 连接成功清零 self::$conn_fail = 0; self::$worker_pid = function_exists('posix_getpid') ? posix_getpid() : 0; mysqli_query(self::$conn, " SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary, sql_mode='' "); } } else { $curr_pid = function_exists('posix_getpid') ? posix_getpid() : 0; // 如果父进程已经生成资源就释放重新生成,因为多进程不能共享连接资源 if (self::$worker_pid != $curr_pid) { self::reset_connect(); } } }
public function connect($config = '', $linkNum = 0) { if (!isset($this->linkID[$linkNum])) { if (empty($config)) { $config = $this->config; } $this->linkID[$linkNum] = new mysqli($config['hostname'], $config['username'], $config['password'], $config['database'], $config['hostport']); if (mysqli_connect_errno()) { throw_exception(mysqli_connect_error()); } if ($this->autoCommit) { $this->linkID[$linkNum]->autocommit(true); } else { $this->linkID[$linkNum]->autocommit(false); } $this->dbVersion = $this->linkID[$linkNum]->server_version; if ($this->dbVersion >= "4.1") { $this->linkID[$linkNum]->query("SET NAMES '" . C('DB_CHARSET') . "'"); } if ($this->dbVersion > '5.0.1') { $this->linkID[$linkNum]->query("SET sql_mode=''"); } $this->connected = true; if (1 != C('DB_DEPLOY_TYPE')) { unset($this->config); } } return $this->linkID[$linkNum]; }
public function open_connection() { $this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME); if (mysqli_connect_errno()) { die("Database connection failed: " . mysqli_connect_error() . "(" . mysqli_connect_errno() . ")"); } }
function getGraphData($users_UserID, $type, $start_date, $end_date) { // Global variables provided by config.php for DB connection. global $con, $host, $user, $password, $db; if (mysqli_connect_errno()) { die('Could not connect: ' . mysqli_connect_error()); } //Initialize index variable. $index = 0; $start_date = new DateTime($start_date); $end_date = new DateTime($end_date); while ($start_date <= $end_date) { $query = "SELECT * FROM sensors WHERE users_UserID = '" . $users_UserID . "' AND Type = '" . $type . "' AND Date >= '" . $start_date->format("Y-m-d") . ' 00:00:00' . "' AND Date <= '" . $start_date->format("Y-m-d") . ' 23:59:59' . "'"; if ($result = mysqli_query($con, $query)) { $rowcount = mysqli_num_rows($result); if ($rowcount == 0) { // No Data for this date -- So fill with 0. $graphdata[$index] = 0; } else { while ($rows = mysqli_fetch_array($result)) { // Insert Data into array. $graphdata[$index] = $rows['Data']; } } mysqli_free_result($result); } else { die('Error:' . mysqli_error($con)); } //Increment Start Date $start_date->modify('+1 day'); //Increment index variable. $index++; } return $graphdata; }