function db_connect() { try { $db = new db_class(); $Connection = $db->connect(); } catch (Exception $e) { echo "Database Connection class not found"; } return $Connection; }
/* Micah's MySQL Database Class - Sample Usage * 4.17.2005 - Micah Carrick, email@micahcarrick.com * * This is a sample file on using my database class. Hopefully it will provide * you with enough information to use the class. You should also look through * the comments in the db.class.php file to get additional information about * any specific function. */ require_once 'db.class.php'; $db = new db_class(); // Open up the database connection. You can either setup your database login // information in the db.class.php file or you can overide the defaults here. // If you setup the default values, you just have to call $db->connect() without // any parameters-- which is much easier. if (!$db->connect('localhost', 'user', 'password', 'database_name', true)) { $db->print_last_error(false); } // Create the table (if it doesn't exist) by executing the external sql // file with the create table SQL statement. echo "Executing SQL commands in external file test_data.sql...<br>"; if (!$db->execute_file('test_data.sql')) { $db->print_last_error(false); } $db->print_last_query(); // This I find very handy. You can build an array as you are working through, // for example, POST variables and validating the data or formatting the data // etc. By defaul, the class will add slashes (addslashes()) to all string data // being input using this function. you can override that by doing: // $db->auto_slashes = false; // You cannot perform any MySQL functions when using insert_array() as the the
function naming_authority($config, $webid) { // set up db $db = new db_class(); $db->connect('localhost', $config['db_user'], $config['db_pwd'], $config['db_name']); $sql = 'select webid, mbox from passwords where webid="' . $webid . '" and active = 1 and publish_mbox_sha1sum = 1 and verified_mbox=1 '; //print $sql . "<br/>"; $results = $db->select($sql); if ($row = mysql_fetch_assoc($results)) { /* if (detect_ie() or detect_safari()) { header('Content-Type: application/xml'); } else { header('Content-Type: application/rdf+xml'); } print '<?xml version="1.0" encoding="ISO-8859-1"?>'. "\n"; print '<rdf:RDF' . "\n"; print 'xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"' . "\n" ; print 'xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"' . "\n"; print 'xmlns:foaf="http://xmlns.com/foaf/0.1/">'. "\n"; print '<rdf:Description rdf:about="">' . "\n"; print '<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/PersonalProfileDocument"/>'. "\n"; print '<foaf:maker rdf:resource="http://webid4.me/#agent"/>' . "\n"; print '<foaf:primaryTopic rdf:resource="http://webid4.me/#agent"/>' . "\n"; print '</rdf:Description>'. "\n"; print '<foaf:Agent rdf:about="http://webid4.me/#agent">' . "\n"; print '<foaf:knows>' . "\n"; print '<foaf:Agent rdf:about="' . $row['webid'] . '">' . "\n"; print '<foaf:mbox_sha1sum>' . sha1($row['mbox']). '</foaf:mbox_sha1sum>' . "\n"; print '</foaf:Agent>' . "\n"; print '</foaf:knows>' . "\n"; print '</foaf:Agent>' . "\n"; print '</rdf:RDF>' . "\n"; */ head("knows"); print '<table border="0" cellspacing="10">'; print "<tr><td>webid: </td><td>" . $row['webid'] . "</td></tr>"; print "<tr><td>mbox_sha1sum: </td><td>" . sha1($row['mbox']) . "</td></tr>"; print "</table>"; print "Signature: <a href='https://" . $_SERVER["SERVER_NAME"] . "/gpg.php?sign=https://" . $_SERVER["SERVER_NAME"] . $_SERVER['REQUEST_URI'] . "'>" . $_GET['webid'] . "</a>"; // print "Export to: <a href='http://www.w3.org/2007/08/pyRdfa/extract?uri=https://webid4.me/?webid=" . $row['webid'] . "&format=pretty-xml&warnings=false&parser=lax&space-preserve=true&submit=Go!&text='>RDF/XML</a>"; print '<div typeof="foaf:PersonalProfileDocument" about="">' . "\n"; print '<div rel="foaf:primaryTopic" href="http://' . $_SERVER["SERVER_NAME"] . '/#agent"/>' . "\n"; print '</div>' . "\n"; print '<div about="http://' . $_SERVER["SERVER_NAME"] . '/#agent" typeof="foaf:Agent">' . "\n"; print '<div rel="foaf:knows">' . "\n"; print '<div about="' . $row['webid'] . '" typeof="foaf:Agent">' . "\n"; print '<div property="foaf:mbox_sha1sum" content="' . sha1($row['mbox']) . '"/>' . "\n"; print '</div>' . "\n"; print '</div>' . "\n"; print '</div>' . "\n"; print '<div about="#key" typeof="wot:PubKey">' . "\n"; print '<div rel="wot:identity" href="#agent"></div>' . "\n"; print '<div rel="wot:pubkeyAddress" href="http://' . $_SERVER["SERVER_NAME"] . '/' . $_SERVER["SERVER_NAME"] . '-pgp.asc"></div>' . "\n"; print '<div property="wot:hex_id" content="2E899F21"></div>' . "\n"; print '<div property="wot:length" content="2048"></div>' . "\n"; print '<div property="wot:fingerprint" content="DCBE32FC0BD85797360BE1D27757B1562E899F21"></div>' . "\n"; print '</div>' . "\n"; print '<div typeof="rdf:Description" about="">' . "\n"; print '<div rel="wot:assurance" href="http://' . $_SERVER["SERVER_NAME"] . '/' . $_SERVER["SCRIPT_NAME"] . '.htm.asc"></div>' . "\n"; print '</div>' . "\n"; } else { main(); } }
<?php include 'head.php'; ?> <body> <div id="wrap"><?php include 'header.php'; ?> <?php require_once "config.php"; require_once "db.class.php"; require_once 'lib/libAuthentication.php'; $db = new db_class(); $db->connect('localhost', $config['db_user'], $config['db_pwd'], $config['db_name']); function printrdf($str) { global $rdf; $rdf .= $str; } $subjectAltName = openssl_get_subjectAltName(); $certrsakey = openssl_pkey_get_public_hex(); $rdf = $_POST['rdf']; if (empty($rdf) || $rdf == '0') { $rdf = '<rdf:RDF'; printrdf(' xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"'); printrdf(' xmlns:cert="http://www.w3.org/ns/auth/cert#"'); printrdf(' xmlns:rsa="http://www.w3.org/ns/auth/rsa#">'); printrdf('<rsa:RSAPublicKey>'); $foaffile = $subjectAltName['URI'] ? $subjectAltName['URI'] : 'TYPE YOUR WEBID HERE';
<?php require_once 'config.php'; require_once 'db/db.class.php'; require_once 'ImageStuffer.php'; $user_id = 1; $db = new db_class(); if (!$db->connect($GLOBALS['db_hostname'], $GLOBALS['db_username'], $GLOBALS['db_password'], $GLOBALS['db_name'], true)) { $db->print_last_error(false); die; } $stuffer = new ImageStuffer(); // open the current directory by opendir $handle = opendir("bimages"); echo 'svn delete '; while (($file = readdir($handle)) !== false) { $filename = 'bimages/' . $file; $extension = substr(strrchr($filename, '.'), 1); $md5 = md5_file($filename); $sql = "SELECT create_time FROM images WHERE md5 = '{$md5}'"; $create_time = $db->select_one($sql); if (!$create_time) { $create_time = filemtime($filename); $stuffer->saveImageToDB($md5, $extension, $user_id, $create_time); rename($filename, 'bimages/' . $md5 . '.' . $extension); echo " {$filename}"; } } closedir($handle);