function buildPage() { global $mysql; $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); if ($result = $MySQLConnection->getQuery('SELECT x.matchID AS matchID, x.matchDate AS matchDate, y.teamName AS matchHomeTeam, y.teamLogo AS matchHomeTeamLogo, z.teamName AS matchForeignTeam, z.teamLogo AS matchForeignTeamLogo FROM matches AS x JOIN teams AS y ON y.teamID = matchHomeTeam JOIN teams AS z ON z.teamID = matchForeignTeam;')) { while ($row = mysqli_fetch_assoc($result)) { $userTips = getUserTips($MySQLConnection, $row["matchID"]); echo ' <div class="panel panel-default"> <form id="match_' . $row["matchID"] . '" method="POST"> <div class="panel-body"> <div class="panel-heading">' . $row["matchHomeTeam"] . ' vs. ' . $row["matchForeignTeam"] . '</div> <div class="input-group"> <label>' . $row["matchHomeTeam"] . '</label> <input type="number"min="0"value="' . $userTips["tipScoreHome"] . '" name="ScoreHome" id="ScoreHome" required/> </div> <div class="input-group"> <label>' . $row["matchForeignTeam"] . '</label> <input type="number"min="0" value="' . $userTips["tipScoreForeign"] . '" name="ScoreForeign" id="ScoreForeign" required/> <input type="button" value="Place Tip" onclick="placeTip(' . $row["matchID"] . ');"/> </div> </div> </form> </div> '; } } }
function buildPage() { global $mysql; $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); if ($result = $MySQLConnection->getQuery('SELECT messageID, messageRecipient, messageSender, messageTime, messageSubject, messageBody, userLogin, userID FROM messages JOIN users ON messageSender = userID WHERE messageRecipient = ' . $_SESSION["userID"] . ' LIMIT 0,25;')) { echo ' <div class="col-md-2"> '; while ($row = mysqli_fetch_object($result)) { $messageJSON = (string) json_encode($row); echo ' <div class="list-group"> <a href="#" onclick="displayMessage(\'' . $row->messageID . '\');"" class="list-group-item"> <p class="list-group-item-text">' . $row->messageTime . ' - ' . $row->userLogin . '</p> <h4 class="list-group-item-heading">' . $row->messageSubject . '</h4> </a> </div> '; } echo '</div>'; } else { echo '<script type="text/javascript">', 'printError(\'Error while getting your messages!\')', '</script>'; } }
function buildPage() { global $mysql; $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); if ($result = $MySQLConnection->getQuery('SELECT * FROM users JOIN countries ON userCountry = iso3166 WHERE userID = ' . $_GET["userID"] . ';')) { while ($row = mysqli_fetch_assoc($result)) { echo ' <div class="col-md-2"> <div class="panel panel-default"> <div class="panel-heading">' . $row["userLogin"] . '</div> <div class="panel-body"> <div class="media"> <div class="media-left"> <a href="img/avatar/' . $row["userAvatar"] . '"> <img class="media-object" src="img/avatar/' . $row["userAvatar"] . '" /> </a> </div> </div> <p><b>First Name: </b>' . $row["userFirstName"] . '</p> <p><b>Last Name: </b>' . $row["userLastName"] . '</p> </div> </div> </div> '; } } }
function printCountrySelect() { global $mysql; $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); $result = $MySQLConnection->getQuery('SELECT * FROM countries;'); echo '<select id="userCountry" name="userCountry"><option value="">---NO COUNTRY SELECTED---</option>'; while ($row = mysqli_fetch_assoc($result)) { echo '<option value="' . $row["iso3166"] . '">' . $row["countryName"] . '</option>'; } echo '</select>'; }
/** * @covers mychaelstyle\storage\providers\Mysql::get * @depends testPut */ public function testGet() { $this->object->connect($this->uri, $this->options); // get contents $contents = $this->object->get('/tmp.txt'); $this->assertEquals(file_get_contents($this->org_example), $contents); // to file $tmp = tempnam(sys_get_temp_dir(), 'tmp_mychaelstyle_storage_mysql_test_'); $result = $this->object->get('/tmp.txt', $tmp); $this->assertTrue($result); $this->assertEquals(file_get_contents($this->org_example), file_get_contents($tmp)); // disconnect $this->object->disconnect(); }
public static function getArticlesByIssue($issue) { $mysql = new Mysql(); $mysql->connect(Config::$bd_servidor, Config::$bd_esquema, Config::$bd_usuario, Config::$bd_contrasena); $query = "select pa.article_id article_id, fojsbus_articlesetting(pa.article_id,'title','es_ES') title\n from published_articles pa\n where pa.issue_id=" . $issue->getId() . ";"; $resultSet = $mysql->query($query); $myArticles = array(); foreach ($mysql->fetchAll($resultSet) as $articleData) { $article = new Article($issue, $articleData['article_id'], $articleData['title']); $myArticles[] = $article; } if (empty($myArticles)) { return null; } return $myArticles; }
public static function getJournalById($journal) { $myJournal = $journal; $mysql = new Mysql(); $mysql->connect(Config::$bd_servidor, Config::$bd_esquema, Config::$bd_usuario, Config::$bd_contrasena); $query = "select j.journal_id journal_id, j.path path, fojsbus_journalsetting(j.journal_id,'title','es_ES') title\n from journals j\n where j.journal_id=" . $myJournal->getId() . ";"; $resultSet = $mysql->query($query); if ($resultSet != false) { $journalData = $mysql->fetchAll($resultSet); if ($journalData[0]['journal_id'] != null && $journalData[0]['journal_id'] != '') { $myJournal->setTitle($journalData[0]['title']); $myJournal->setUrl(Config::$ojs . "/" . $journalData[0]['path']); $myJournal->setIssues(IssueDAO::getIssuesByJournal($myJournal)); return $myJournal; } } return null; }
public static function getIssuesByJournal($journal) { $mysql = new Mysql(); $mysql->connect(Config::$bd_servidor, Config::$bd_esquema, Config::$bd_usuario, Config::$bd_contrasena); $query = "select i.issue_id issue_id, i.volume volume, i.number number, i.year year, fojsbus_issuesetting(i.issue_id,'title','es_ES') title\n from issues i LEFT JOIN custom_issue_orders o ON (o.issue_id = i.issue_id) \n where i.journal_id=" . $journal->getId() . "\n and i.published = 1 \n order by o.seq ASC, i.current DESC, i.date_published DESC;"; $resultSet = $mysql->query($query); $myIssues = array(); if ($resultSet != false) { foreach ($mysql->fetchAll($resultSet) as $issueData) { $issue = new Issue($journal, $issueData['issue_id'], $issueData['volume'], $issueData['number'], $issueData['year'], $issueData['title']); $issue->setArticles(ArticleDAO::getArticlesByIssue($issue)); $myIssues[] = $issue; } } if (empty($myIssues)) { return null; } return $myIssues; }
function performLogin($credentials, $mysql) { $JSONerror->state = 0; $JSONerror->message = 'Success'; //Connect to MySQL DB $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); if (verifyCredentials($credentials, $MySQLConnection)) { $userObject = getUserInfo($credentials, $MySQLConnection); if ($userObject->userValid) { sessionInit($userObject, false); echo json_encode($userObject); } else { $JSONerror->state = 1; $JSONerror->message = 'User blocked!'; print_r(json_encode($JSONerror)); } } else { $JSONerror->state = 1; $JSONerror->message = 'Your Password and Username combination does not Match our databse, Sorry'; print_r(json_encode($JSONerror)); } }
<?php define("SQL_SINGLE_VALUE", 1000); define("SQL_SINGLE_ROW", 1001); define("SQL_SINGLE_COLUMN", 1002); define("SQL_MULTIPLE_ROWS", 1003); $allowed_for_guests = array("index.php", "about.php", "contact.php", "products.php", "login.php"); session_start(); spl_autoload_register('myclass__autoload'); Mysql::connect("localhost", "csc2720", "addoil", "csc2720"); //Mysql::connect("localhost", "root", "", "csc2720"); $user = User::logged_in_user(); if (!$user instanceof User && !in_array(after_last("/", $_SERVER["SCRIPT_NAME"]), $allowed_for_guests)) { set_msg("Please login first"); header("Location: index.php"); exit; } function myclass__autoload($class_name) { if (file_exists("classes/{$class_name}.php")) { require_once "classes/{$class_name}.php"; } } function sql($query, $limit = 1003) { return Mysql::query($query, $limit); } function dbstr($data, $delimiter, $isField = true) { $first = 1; $ret = "";
</a>:: <a href="?seccion=aisgc_admin&aktion=change"><?php echo AUDITORIAS_CAMBIAR_AUDITORIA; ?> </a> </td> </tr> </tbody> </table> <br> <?php require_once "../includes/ErrorManager.class.php"; require_once "../includes/Mysql.class.php"; $mysql = new Mysql(); $mysql->connect("localhost", "donkey", "root", ""); // change this line here // requires the class require "../class.datepicker.php"; // instantiate the object $db = new datepicker(); // uncomment the next line to have the calendar show up in german //$db->language = "dutch"; $db->firstDayOfWeek = 1; // set the format in which the date to be returned $db->dateFormat = "Y-m-d"; // Aktionen $aktion = ''; if (isset($_GET['aktion'])) { $aktion = $_GET['aktion']; }
} else { $string .= ',' . $this->setQuoteStyle($key) . "='" . $this->safeFilter($val) . "'"; } } $sql = 'UPDATE ' . $this->setQuoteStyle($table) . ' SET ' . $string . ($where === NULL ? $where : ' WHERE ' . $where); echo $sql; exit; //mysql_query ( $sql, $this->_link ); } function delete($table, $where = NULL) { $sql = 'DELETE FROM ' . $this->setQuoteStyle($table) . ($where == NULL ? $where : ' WHERE ' . $where); echo $sql; //mysql_query ( $sql, $this->_link ); } function setQuoteStyle($key) { //添加方法对其表名,字段名称进行添加反引号; return '`' . $key . '`'; } function safeFilter($value) { //当插入数据有单引号或其他符号引起SQL注入安全时,需要对其进行过滤,使用mysql_real_escape_string()函数 return mysql_real_escape_string($value, $this->_link); } } // 创建对象 $bind = array('username' => "1'2", 'password' => "2'2", 'age' => 3, 'sex' => 0); $db = new Mysql(); $db->connect('localhost', 'root', 'root', 'test'); $db->insert('users', $bind);
$starttime = $mtime[0] + $mtime[1]; require TOA_ROOT . 'include/function_cache.php'; require TOA_ROOT . 'include/function_version.php'; require TOA_ROOT . 'include/function_global.php'; define('template', TOA_ROOT . 'template/default/'); if (!get_magic_quotes_gpc()) { $_GET = add_slashes($_GET); $_POST = add_slashes($_POST); $_COOKIE = add_slashes($_COOKIE); } $_FILES = add_slashes($_FILES); !$_SERVER['PHP_SELF'] && ($_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME']); $superadmin = ''; require TOA_ROOT . 'config.php'; require TOA_ROOT . 'include/class_mysql.php'; require TOA_ROOT . 'include/class_user.php'; require TOA_ROOT . 'include/class_config.php'; require TOA_ROOT . 'include/function_common.php'; require TOA_ROOT . 'include/excel_writer.class.php'; require TOA_ROOT . 'include/class_Utility.php'; require TOA_ROOT . 'include/class_ugcode.php'; require TOA_ROOT . 'include/sms.class.php'; require TOA_ROOT . 'include/class_ads.php'; require TOA_ROOT . 'include/word.class.php'; $db = new Mysql(); $db->connect(DB_HOST, DB_USER, DB_PWD, DB_NAME, DB_PCONNECT); $_CONFIG = new config(); $_ADS = new ads(); $_USER = new User(); $_CACHE = $_FILTER = $_FILTER_SORT = $_ACTION = array(); obstart();
function __construct() { $this->pdo = Mysql::connect(); }
<?php $JSONerror = new stdClass(); include_once 'mysql.class.php'; include_once 'include/conf.php'; if (isset($_POST)) { if (isset($_POST['userLogin']) && isset($_POST['userPassword']) && isset($_POST['userEmail']) && $_POST['userPassword'] == $_POST['userPasswordRepeat']) { $userData = $_POST; $userData["userPassword"] = password_hash((string) $userData['userPassword'], PASSWORD_DEFAULT); $MySQLConnection = new Mysql($mysql['host'], $mysql['port'], $mysql['user'], $mysql['password'], $mysql['database']); $MySQLConnection->connect(); if ($MySQLConnection->getQuery('INSERT INTO users (userLogin, userPassword, userEmail, userFirstName, userLastName, userGender, userBirthDay, userValid, userCountry) VALUES ("' . $userData["userLogin"] . '","' . $userData["userPassword"] . '","' . $userData["userEmail"] . '","' . $userData["userFirstName"] . '","' . $userData["userLastName"] . '","' . $userData["userGender"] . '","' . $userData["userBirthDay"] . '",0,"' . $userData["userCountry"] . '");')) { $JSONerror->state = 0; $JSONerror->message = 'Success!'; print_r(json_encode($JSONerror)); } else { $JSONerror->state = 1; $JSONerror->message = 'MySQL Error!'; print_r(json_encode($JSONerror)); } } else { $JSONerror->state = 1; $JSONerror->message = 'Some Fields contain invalid Data!'; print_r(json_encode($JSONerror)); } } else { $JSONerror->state = 1; $JSONerror->message = 'General Error!'; print_r(json_encode($JSONerror)); }
//setup database }); $spec->it("should connect to database", function ($spec) { $adapter = new Mysql(); try { $adapter->connect("localhost", "root", ""); $adapter->force_connection(); $spec(true)->should->be(true); } catch (ConnectionException $e) { $spec(true)->should->be(false); } }); $spec->it("should throw exception when trying to connect with invalid data", function ($spec) { $adapter = new Mysql(); try { $adapter->connect("localhost", "root", "wrong"); $adapter->force_connection(); $spec(true)->should->be(false); } catch (ConnectionException $e) { $spec(true)->should->be(true); } }); $spec->context("doing queries", function ($spec) { $spec->before_all(function ($data) { $data->adapter = new Mysql(); $data->adapter->connect("localhost", "root", ""); $data->adapter->select_db("limber_record"); }); $spec->it("should return an array data for selections", function ($spec, $data) { $cars = $data->adapter->select("SELECT name FROM `cars`"); $spec($cars)->should->be(array(array("name" => "Ferrari"), array("name" => "Lamborguini"), array("name" => "BMW")));
<?php require_once "ErrorManager.class.php"; require_once "Mysql.class.php"; ?> <?php try { // <<<<-------------- try $mysql = new Mysql(); $mysql->connect("HOST", "DATABASE", "USER", "PASSWORD"); // change this line here $query = "select * from categories"; // and table name here $result = $mysql->query($query); ?> <ul> <?php foreach ($mysql->fetchAll($result) as $category) { ?> <li><?php print_r($category); ?> </li> <?php } ?> </ul>
* * @return bool|\mysqli_result */ public function runSql($query) { return $this->sql->query($query); } /** * @return int */ public function errno() { return $this->sql->errno; } /** * @return string */ public function error() { return $this->sql->error; } public function close() { $this->sql->{$this}->sql->close(); } } $query = "select * from aao WHERE id LIKE '201446%'"; $results = Mysql::connect('neu')->getVar($query); var_dump(Mysql::connect()->get_client_info()); var_dump(Mysql::connect()->get_server_info()); var_dump($results);
public static function load($configs = false) { if (self::$connect === null) { self::$connect = new self($configs); } return self::$connect; }
{ public function select() { echo 'The class "', __METHOD__, '" was initiated!<br />'; } } class Mssql extends Database { public function connect() { echo 'The class "', __METHOD__, '" was initiated! User : '******' Pass : '******'<br />'; } public function select() { echo 'The class "', __METHOD__, '" was initiated!<br />'; } } $db = new Mysql(); $db->authentication('root', 'root'); $db->connect(); $db->select(); echo "<hr>"; $db = new Postgresql(); $db->authentication('root', 'root'); $db->connect(); $db->select(); echo "<hr>"; $db = new Mssql(); $db->authentication('ali', 'root'); $db->connect(); $db->select();