I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
function AddToDB($tbl) { // Set the arrays we'll need $sql_columns = array(); $sql_columns_use = array(); $sql_value_use = array();
// Pull the column names from the table $tbl $pull_cols = mysql_query("SHOW COLUMNS FROM ".$tbl) or die("MYSQL ERROR: ".mysql_error());
// Pull an associative array of the column names and put them into a non-associative array while ($columns = mysql_fetch_assoc($pull_cols)) $sql_columns[] = $columns["Field"];
foreach( $_POST as $key => $value ) { // Check to see if the variables match up with the column names if ( in_array($key, $sql_columns) && trim($value) ) { // If this variable contains the string "DATESTAMP" then use MYSQL function NOW() if ($value == "DATESTAMP") $sql_value_use[] = "NOW()"; else { // If this variable contains a number, then don't add single quotes, otherwise check to see // if magic quotes are on and use addslashes if they aren't if ( is_numeric($value) ) $sql_value_use[] = $value; else $sql_value_use[] = ( get_magic_quotes_gpc() ) ? "'".$value."'" : "'" .addslashes($value)."'"; } // Put the column name into the array $sql_columns_use[] = $key; } }
// If $sql_columns_use or $sql_value_use are empty then that means no values matched if ( (sizeof($sql_columns_use) == 0) || (sizeof($sql_value_use) == 0) ) { // Set $Error if no values matched $this->Error = "Error: No values were passed that matched any columns."; return false; } else { // Implode $sql_columns_use and $sql_value_use into an SQL insert sqlstatement $this->SQLStatement = "INSERT INTO ".$tbl." (".implode(",",$sql_columns_use). ") VALUES (".implode(",",$sql_value_use). ")";
// Execute the newly created statement if ( @mysql_query($this->SQLStatement) ) return true; else { // Set $Error if the execution of the // statement fails $this->Error = "Error: ".mysql_error(); return false; } } } // end func
// If $sql_value_use is empty then that means no values matched if ( sizeof($sql_value_use) == 0 ) { // Set $Error if no values matched $this->Error = "Error: No values were passed that matched any columns."; return false; } else { // Implode $sql_value_use into an SQL insert sqlstatement $this->SQLStatement = "UPDATE ".$tbl." SET ".implode(",",$sql_value_use)." WHERE ".$id_name."=".$id;
// Execute the newly created // statement if ( @mysql_query($this->SQLStatement) ) return true; else { // Set $Error if the execution of the statement fails $this->Error = "Error: ".mysql_error(); return false; } } } // end func
function UpdateDB($tbl, $id, $id_name) { // Set the arrays we'll need $sql_columns = array(); $sql_value_use = array();
// Pull the column names from the table $tbl $pull_cols = mysql_query("SHOW COLUMNS FROM ".$tbl) or die( "MYSQL ERROR: ".mysql_error() );
// Pull an associative array of the column names and put them into a non-associative array while ($columns = mysql_fetch_assoc($pull_cols)) $sql_columns[] = $columns["Field"];
foreach($_POST as $key => $value) { // Check to see if the variables match up with the column names if ( in_array($key, $sql_columns) && isset($value) ) { // If this variable contains the string "DATESTAMP" then use MYSQL function NOW() if ($value == "DATESTAMP") $sql_value_use[] = $key."=NOW()"; else { // If this variable contains a number, then don't add single quotes, otherwise check to see // if magic quotes are on and use addslashes if they aren't if ( is_numeric($value) ) $sql_value_use[] = $key."=".$value; else $sql_value_use[] = ( get_magic_quotes_gpc() ) ? $key."='".$value."'" : $key."= '".addslashes($value)."'"; } } }
// If $sql_value_use is empty then that means no values matched if ( sizeof($sql_value_use) == 0 ) { // Set $Error if no values matched $this->Error = "Error: No values were passed that matched any columns."; return false; } else { // Implode $sql_value_use into an SQL insert sqlstatement $this->SQLStatement = "UPDATE ".$tbl." SET ".implode(",",$sql_value_use)." WHERE ".$id_name."=".$id;
// Execute the newly created // statement if ( @mysql_query($this->SQLStatement) ) return true; else { // Set $Error if the execution of the statement fails $this->Error = "Error: ".mysql_error(); return false; } } } // end func
Der står: function MyDatabase() { // Config for the database // connection $this->DBUser = "tmp_usr"; $this->DBPass = "<A href="mailto:super#secret@pass">super#secret@pass</A>"; $this->DBName = "c_test"; $this->DBHost = "localhost"; }
function Connect() { //Connect to a mysql database $this->db = mysql_connect($this->DBHost, $this->DBUser, $this->DBPass) or die("MYSQL ERROR: ".mysql_error()); // Select the database mysql_select_db($this->DBName, $this->db) or die("MYSQL ERROR: ".mysql_error()); }
// Disconnect from the MYSQL database function Disconnect() { mysql_close($this->db) or die("MYSQL ERROR: ".mysql_error()); } }
Men jeg har altid åbnet databasen unden denne kode det har ikke givet problemer før nu. Dvs. ikke brugt den her kode.
if (isset($_POST['send'])) { opendb(); $_POST['newsbody'] = nl2br($_POST['newsbody']); AddToDB(news); msgandlink("Du har nu gemt nyheden"); closedb(); }
$db = mysql_connect("$_SESSION[server]", "$_SESSION[bruger]", "$_SESSION[kodeord]"); if (!$db) { error("Kunne ikke oprette en forbindelse til MySQL."); exit; } // vælg base der skal arbejdes med $checkBaseConnect = mysql_select_db($_SESSION['database'],$db);
function opendb() { // Connect to a mysql database $this->db = mysql_connect($this->DBHost, $this->DBUser, $this->DBPass) or die("MYSQL ERROR: ".mysql_error()); // Select the database mysql_select_db ($this->db, $this->{$this->DBConnection}) or die("MYSQL ERROR: ".mysql_error()); }
// Disconnect from the MYSQL database function closedb() { mysql_close($this->db) or die("MYSQL ERROR: ".mysql_error()); } }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.