-
Posts
848 -
Joined
-
Last visited
-
Days Won
2 -
Feedback
66.7%
Everything posted by Wife
-
Yes please, then I could instead of posting these just dislike people who I don't like personally. Great.
-
You can not run from the fact they are coming.
-
No hell no. Beautiful syntax isn't always the best..
-
Uh? PDO wraps strings automaticly.
-
Formatting somehow messed up when correcting an error with phone.
-
Because I know the code itself works. There might be typos or such things like that. It's not that an tutorial is supposed to be something where your kind can ctrl-ca and ctrl-v
-
when you've had such a primo night that you're happy enough to sleep at 9pm
Wife replied to Spookz's topic in Spam/Off Topic
A sign. A sign of they are coming. -
Hello, Okay, so in this tutorial we will be creating a dynamic PHP Script, that changes database values when the correct user agent is requesting your server, and creating another PHP file for fetching that data from the database. No fancy design here, if you are after that - stop reading. Part 1. What is User Agent? User agent is a software application 'agent' that performs tasks behalf of a user. We can use user agent for our PHP script only allowing requests from a certain user agent. Useful in cases for example dynamic signatures and other tasks that we want to apply automation on. Example of User Agent usage $ua_name = "FacialSlave"; //The name of expected user agent $ua = $_SERVER['HTTP_USER_AGENT']; if(!preg_match('/'.$ua_name.'/', ua)) { //Returns false if incorrect HTTP_REQUEST echo '<h1>Invalid user agent.</h1>'; } else if(isset($_GET['variable'])) { //If above returns true let's execute our statement defined somewhere. $statement->execute(); } Note! You need also to define the user agent from the other end of your application, in this we would be creating a dynamic script leaderboard, so you need to define the user agent from your Java files also, like this private static final String USER_AGENT = "FacialSlave"; Part 1.5 The Java side for this app The Java side not exactly what this guide is about, I'm just going to briefly talk this through. //Variables private static final String URL = "http://localhost/pdo_updateDatabase.php?"; private static final String USER_AGENT = "FacialSlave"; //Actual code public static void httpAgent(String var_str, int var_int) { String urlStr = URL + "variableOne=" + var_str + "&var_int=" + var_int; StringBulder http = new StringBuilder(); URL url; try { url = new URL(urlStr); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.addRequestProperty("User-Agent", USER_AGENT); BufferedReader brd = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while((line = brd.readLine()) != null) { result.append(line); } brd.close(); } catch (Exception err) { } } Part 2. SET Query for updating data in database SET changes already existing data in database to new given values require 'pdo_dbConnection.php'; //UA CHECK ... Now if the user agent is correct, let's start executing our qery else if(isset($_GET['variableOne'] && $_GET['var_int'])) { //Query, where we set value of variableOne from Table where integerValue equals to given integer $query = 'UPDATE Table SET variableOne = :variableOne WHERE integerValue = :var_int'; //Preparing the query above $statement = $connection->prepare("$query"); //Executing statement as array, where we define placeholders for the query $statement->execute(array( ':variableOne' => $_GET['variableOne], ':var_int' => $_GET['var_int'] )); echo 'Updated successfully.'; } Part 2.5 Fetching data from our database Fetching data can be done in multiple ways, this is just one example of it. require 'pdo_dbConnection.php'; $query = 'SELECT * FROM Table'; //Query, * is a wildcard for selecting ALL fields from table. //Using * is not recommended in production environment. $statement = $connection->prepare($query); //And again, preparing the query for connection. $statement->execute(); //Executing statement. //Fetching data foreach($statement as $row) { echo ' <table style="width=250px"> <tr> <th>My Script</th> </tr> <tr> <td>Variable One: '.$row['variableOne'].'</td> <td>Variable Two: '.$row['variableTwo'].'</td> </tr> </table> '; } I have NOT tested the code above, just wrote it. If you face any errors with my code, please let me know and I will take a look at it. Because I do make often alot of easy typos etc.
-
.. they are coming, what will you do?
-
You are very welcome. I just corrected a mistake where I was trying to call the getMessage function from connection variable, where I was supposed to get it from the PDOException variable error.. Thanks
-
Thanks. Appreciate this.
-
Hello, So, because I am already being hated by many people I decided to give you something a little bit more productive this time. 1. The Basics What is PDO? PDO stands for PHP Data Objects which simply is a object based database library. One of the biggest advantages of PDO apart from it being very secure and light weight (when used correctly, of course) is the fact that it is a abstract level library for database methods and works pretty much widely on every well known database server. The library consists from bunch of classes containing methods and functions for database queries. Example of usage $statement = $connection->prepare($query);$statement->execute(); In PDO, when you are passing variables to query, they are defined AFTER preparing the query, while/or before executing it.Example of variables in PDO query $query = 'SELECT * FROM users WHERE username = :username'; //We use 'placeholders' :username is a placeholder$statement = $connection->prepare($query);$statement->execute(array(':username' => $username)); So, this way the variable - which can be assigned from HTTP_REQUEST or via static methods, is never passed directly to the query and helps us prevent error based SQL injection. Fetching data, data types //Fetching data as an array$result = $statement->fetch(PDO::FETCH_ASSOC);print_r($result);//Alternative, for looping all the results found for statementforeach($statement as $row) {echo '$row['data'];} //So here the result of $statement->execute is assigned as $row and data can be accessed using $row['datafield']; $row['datafield2'];//etc, based on your database table names.//Fetching data as object (I have to include this as we are talking about DATA OBJECTS$result = $statement->fetch(PDO::FETCH_OBJ);echo $result->username;echo $result->othervalue;//Ok so this is the object oriented method, where fetch returns an object where property names are assigned from result. It is also possible to return all the remaining values from data set by using fetchAll(); method. Usage defined above.You can see a complete list of PHP datatypes online. Establishing a database connection //Okay, this should be pretty straight forward. The connection is handled inside try{} and catch(){} blocks.try {//Variables for username and password$username = 'db_user';$password = 'db_password';//This creates a new PDO object for variable $connection. Connection details are//mysql:host, dbname, $username, $password$connection = new PDO('mysql:host=localhost;dbname=database_name', $username, $password);//Let's set the attribute errormode to pdo error mode exception for our catch() block.$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);} catch (PDOException $error) {//getMessage() us any possible errors with connecting, die(); is for killing the connection.$error->getMessage();$connection->die();} Part 2. Coming tomorrow, and then we will be actually creating something, a dynamic database SET query using USER_AGENT and then outputting the data.
-
Sir, let me remind you that we will provide you with each and everything (mostly everything) legal documents. We are a legit business.
-
Hello Mr. Orange, First I would like to say that I really appreciate that you took your personal time and effort as the acting leader of your organization "The Real TWC club". We are also actively looking for partners from all non-profit organizations that share the same interests we do. It is very important for us to unite, and spread the word and awareness about them coming. Looking forward to your reply, and have a nice psychosis. Thank you, Mr. Facial Acting secretary, The International They Will Come What Will You Do Organization 35455, Foil st. North Psychosis, United States of Legal Drugs (also illegal) info@titwcwwydo.org
-
They Will Come is now The International They Will Come What Will You Do -organization.
-
It's seems like during the 3 days of my stay here, ez11 has already developed a trust issue towards me, so that kind of counts me in to your club. But I am still the manager and acting chairsman at the International They Will Come What Will You Do non-profit organization.
-
Absolutely sir, and I also work as a Certified Microsoft Technician, and my name is Bob Johnson, how may I help you? Your computer is it a dekstop or a laptop? There appears to be some Wiruses on your PC that are trying to hack your ip.
-
Can someone design a logo for our club. They logo should say They Will Come or TWC.
-
What is that? How can I get something that is in future form of time? They Will come
-
This is the official thread for the They Will Come -club If you want to join, please sign this page by posting anything. We are ready when They come and we will laugh to all non-believers.
-
Let's go.
-
Okay, since it's clear that they actually are coming I decided to make a thread, where we can have serious discussion about them, and share tips and tops about what to do, when they come. I know they are coming, because they told me so in a message they sent to my foil hat with antenna extension. I've also prepared by building a dugout in nearby forest. I am going to fight them off as long as I can, until the last dying breath. The question that lies here is what are you going to do when they come?