本文整理汇总了PHP中GetConnection函数的典型用法代码示例。如果您正苦于以下问题:PHP GetConnection函数的具体用法?PHP GetConnection怎么用?PHP GetConnection使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetConnection函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetMainConnection
function GetMainConnection()
{
global $MainConnection;
if (!isset($MainConnection)) {
$MainConnection = GetConnection(DB_HOST, DB_PORT, DB_NAME, DB_CHARSET, DB_USER, DB_PASSWORD);
}
return $MainConnection;
}
示例2: run
public function run()
{
global $connection_string;
global $last_migration;
$migrations = array();
try {
$migrations = MigrationHistory::find('all', array('order' => 'migration_date desc'));
} catch (Exception $e) {
//error_log($e);
$create_migration_history = "CREATE TABLE `migration_history` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `migration_timestamp` bigint(20) DEFAULT NULL,\n\t\t\t `migration_file` varchar(100) DEFAULT NULL,\n\t\t\t `migration_date` datetime DEFAULT NULL,\n\t\t\t `datecreated` datetime NOT NULL,\n\t\t\t PRIMARY KEY (`id`)\n\t\t\t) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=utf8";
GetConnection()->query($create_migration_history);
}
$last_migration_timestamp = strtotime($last_migration);
//if(count($migrations) > 0){
// $last_migration_timestamp = $migrations[0]->migration_timestamp;
//}
$migrations_ran = array_map(function ($m) {
return $m->migration_file;
}, $migrations);
//$last_migration_date = new DateTime("@$last_migration_timestamp");
$migrationFiles = array();
if (is_dir($this->dir)) {
if ($dh = opendir($this->dir)) {
while (false !== ($file = readdir($dh))) {
if ($file != "." && $file != ".." && filetype($this->dir . "/" . $file) == "file") {
$migrationFiles[] = $file;
}
}
sort($migrationFiles);
closedir($dh);
}
}
foreach ($migrationFiles as $file) {
$file_parts = split('_', $file);
$datestamp = $file_parts[0];
$timestamp = strtotime($datestamp);
if ($timestamp > $last_migration_timestamp && !in_array($file, $migrations_ran)) {
error_log("executing " . $file . ": " . $timestamp);
try {
$sqlpipe = "/usr/bin/mysql " . $connection_string . " < \"" . $this->dir . "/" . $file . "\" 2>&1 1> /dev/null";
$return = shell_exec($sqlpipe);
if (!is_null($return)) {
throw new Exception("Migration failed: " . $return);
}
$migrationHistory = new MigrationHistory();
$migrationHistory->migration_timestamp = $timestamp;
$migrationHistory->migration_file = $file;
$migrationHistory->migration_date = date("Y-m-d H:i:s", $timestamp);
$migrationHistory->datecreated = GetNewDate();
$migrationHistory->save();
$last_migration_timestamp = $timestamp;
} catch (Exception $e) {
error_log($e);
break;
}
}
}
}
示例3: Get
static function Get()
{
$conn = GetConnection();
$results = $conn->query("SELECT * FROM 2015Fall_Persons");
$row = $results->fetch_assoc();
//var_dump($row);//=> its like "print(r);"
//echo '<pre>'
//print_r
my_print($row);
}
示例4: Update
static function Update($row)
{
$conn = GetConnection();
$sql = "UPDATE Admin " . "Set Username='{$row['Username']}',Password='{$row['Password']}',Last_log='{$row['Last_log']}' " . "WHERE id={$row['id']} ";
//echo $sql;
$conn->query($sql);
$error = $conn->error;
$conn->close();
return $error != '' ? array('Server Error' => $error) : true;
}
示例5: Update
static function Update($row)
{
$conn = GetConnection();
$sql = "UPDATE Suppliers " . "Set FirstName='{$row['FirstName']}',LastName='{$row['LastName']}',created_at='{$row['created_at']}',updated_at='{$row['updated_at']}',Keyword_id='{$row['Keyword_id']}' " . "WHERE id={$row['id']} ";
//echo $sql;
$conn->query($sql);
$error = $conn->error;
$conn->close();
return $error != '' ? array('Server Error' => $error) : true;
}
示例6: Delete
public static function Delete($id)
{
$conn = GetConnection();
$sql = "DELETE FROM 2014Fall_Food_Eaten WHERE id = {$id}";
//echo $sql;
$results = $conn->query($sql);
$error = $conn->error;
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例7: TestLogin
function TestLogin($pseudo, $password)
{
$db = GetConnection();
$request = $db->prepare('SELECT idUser, pseudo, pwd FROM `users` WHERE pseudo = "' . $pseudo . '" AND pwd = "' . $password . '"');
$request->execute();
$tabUser = $request->fetchAll(PDO::FETCH_ASSOC);
if ($tabUser != null) {
return $tabUser[0]["idUser"];
} else {
return false;
}
}
示例8: Save
public static function Save($row)
{
if ($row['id']) {
$sql = "UPDATE 2015Fall_Meals Set Name = '{$row['Name']}', Calories = '{$row['Calories']}', Carbohydrates = '{$row['Carbohydrates']}', " . "Cholestrol='{$row['Cholestrol']}', Fiber = '{$row['Fiber']}', Protein = '{$row['Protein']}', Users_id=1, 2015Fall_MealTypes_id={$row['MealType']} WHERE id={$row['id']} ";
} else {
$sql = "Insert Into 2015Fall_Meals (Name, Calories, Carbohydrates, Cholestrol, Fiber, Protein, Users_id, 2015Fall_MealTypes_id) " . " Values ('{$row['Name']}', '{$row['Calories']}', '{$row['Carbohydrates']}', '{$row['Cholestrol']}', '{$row['Fiber']}', '{$row['Protein']}', 1, {$row['MealType']})";
}
$conn = GetConnection();
$results = $conn->query($sql);
$error = $conn->error;
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例9: Save
public static function Save($row)
{
if ($row['id']) {
$sql = "Update 2015Fall_Users set Name='{$row['Name']}', Age='{$row['Age']}', Height='{$row['Height']}', Weight='{$row['Weight']}', Avatar='{$row['Avatar']}', Status='offline' WHERE id= {$row['id']}";
} else {
$sql = "Insert Into 2015Fall_Users (Name, Age, Height, Weight, Avatar, Status) Values ( '{$row['Name']}', '{$row['Age']}', '{$row['Height']}', '{$row['Weight']}', '{$row['Avatar']}', 'offline' )";
}
$conn = GetConnection();
$results = $conn->query($sql);
$error = $conn->error;
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例10: Save
public static function Save(&$row)
{
$conn = GetConnection();
$row2 = escape_all($row, $conn);
//my_print( $sql );
$results = $conn->query($sql);
$error = $conn->error;
if (!$error && empty($row['id'])) {
$row['id'] = $conn->insert_id;
}
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例11: Save
public static function Save($row)
{
if ($row['id']) {
$sql = "UPDATE Exercises " . " Set Name = '{$row['Name']}', Minutes='{$row['Minutes']}', Calories_Burned='{$row['Calories_Burned']}', Users_id='{$row['Users_id']}', 2015Fall_ExerciseTypes_id='{$row['Users_id']}' " . " WHERE id={$row['id']} ";
} else {
$sql = "Insert Into Exercises (Name, Minutes, Calories_Burned, ) Values ('{$row['Name']}', '{$row['Minutes']}', '{$row['Calories_Burned']}', '{$row['Users_id']}', )";
}
$conn = GetConnection();
$results = $conn->query($sql);
$error = $conn->error;
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例12: Save
public static function Save($row)
{
if ($row['id']) {
$sql = "UPDATE Friend " . " Set Name = '{$row['Name']}', Friend_id='{$row['Friend_id']}', Users_id='{$row['Person_id']}' WHERE Friend_id={$row['id']} ";
} else {
$sql = "Insert Into Friends (Friend_id, Person_id) Values('{$row['Friend_id']}', '{$row['Person_id']}')";
}
$conn = GetConnection();
$results = $conn->query($sql);
$error = $conn->error;
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例13: FetchAll
function FetchAll($sql)
{
$ret = array();
$conn = GetConnection();
$results = $conn->query($sql);
$error = $conn->error;
if ($error) {
echo $error;
} else {
while ($rs = $results->fetch_assoc()) {
$ret[] = $rs;
}
}
return $ret;
}
示例14: Save
public static function Save(&$row)
{
$conn = GetConnection();
if (!empty($row['id'])) {
$sql = "Update Persons set Name='{$row['Name']}', Age='{$row['Age']}', Height='{$row['Height']}', Weight='{$row['Weight']}', Avatar='{$row['Avatar']}', Status='offline' WHERE id= {$row['id']}";
} else {
$sql = "Insert Into Persons (Name, Age, Height, Weight, Avatar, Status) Values ( '{$row['Name']}', '{$row['Age']}', '{$row['Height']}', '{$row['Weight']}', '{$row['Avatar']}', 'offline' )";
}
//my_print( $sql );
$results = $conn->query($sql);
$error = $conn->error;
if (!$error && empty($row['id'])) {
$row['id'] = $conn->insert_id;
}
$conn->close();
return $error ? array('sql error' => $error) : false;
}
示例15: Save
public static function Save(&$row)
{
$conn = GetConnection();
$row2 = escape_all($row, $conn);
$row2['date'] = date('Y-m-d H:i:s', strtotime($row2['date']));
if (!empty($row['id'])) {
$sql = "Update exercises\n\t\t\t\t\t\tSet exercisename='{$row2['exercisename']}', date='{$row2['date']}' ,calories='{$row2['calories']}',updated=Now(),minutes='{$row2['minutes']}'\n\t\t\t\t\tWHERE id = {$row2['id']}\n\t\t\t\t\t";
} else {
$sql = "INSERT INTO exercises\n\t\t\t\t\t(exercisename, date, created,calories,minutes)\n\t\t\t\t\tVALUES ('{$row2['exercisename']}', '{$row2['date']}', Now() , '{$row['calories']}', '{$row['minutes']}')";
}
$results = $conn->query($sql);
$error = $conn->error;
if (!$error && empty($row['id'])) {
$row['id'] = $conn->insert_id;
}
$conn->close();
return $error ? array('sql error' => $error) : false;
}