
vic vance
Members-
Posts
17 -
Joined
-
Last visited
Everything posted by vic vance
-
I get what you mean, and I was forgot a return. I changed this also: $con = new PDO('mysql:host=localhost;dbname=project', $this->user, $this->pass); return new PDO('mysql:host=localhost;dbname=project', $this->user, $this->pass); Thank you.
-
Hey I was trying out PDO, and I got a minor error: Fatal error: Call to undefined method connection::prepare() on line 12 This is my connect.php class <?php class connection { private $user; private $pass; public function __construct() { $this->user = "lala"; $this->pass = "28282"; } public function dbConnect() { try { $dbh = new PDO('mysql:host=localhost;dbname=project', $this->user, $this->pass); array(PDO::ATTR_PERSISTENT => true); } catch (PDOException $e) { print "<b>Connection Failed:</b> ".$e->getMessage().""; die(); } } } ?> This is the index.php <?php error_reporting(E_ALL ^ E_NOTICE); define( 'ROOT', "./" ); define( 'temp', "templates/" ); require_once 'connect.php'; $con = new connection(); $con->dbConnect(); $head = implode("", file(temp."head.html")); echo $head; $stmt = $con->prepare('SELECT * FROM db_members'); // error here LINE 12 $stmt->execute(); $result = $stmt->fetchAll(\PDO::FETCH_OBJ); foreach($result as $row){ print($row->username); } $foot = implode("", file(temp."/foot.html")); echo $foot; ?> I know I am connected because when I remove the connect.php class and try connecting directly it seems to work: $con = new PDO('mysql:host=localhost;dbname=project', 'lala', '28282'); // removed the class and directly connected $head = implode("", file(temp."head.html")); echo $head; $stmt = $con->prepare('SELECT * FROM db_members'); // error goes away and everything works when I directly connect $stmt->execute(); Am I calling the connect.php class wrong? Please help, Thank you.
-
Hey, I am coding this forum and the following PDO prepare query calls the topic details. The prepare query works perfectly well, however when I add it into a function within another class and then call it, the script does not seem to work. I get errors like the following: Fatal error: Call to a member function fetch() on a non-object in C:\wamp\www\new\sources\forum\new.php on line 117 The prepare query fails to excute, this is because I do not know how to add it into a function. This is what I tried: class FUNC { function userDetails($table, $column, $cVaulue, $oBy, $ASDSC) { global $dbh; $sth = $dbh->prepare('SELECT * FROM `'.$table.'` WHERE `'.$column.'` = '.$cVaulue.' ORDER BY `'.$oBy.'` '.$ASDSC.''); $sth->bindParam(':id', $id, PDO::PARAM_INT); $sth->execute(); } } The FUNC class is called as the $load variable, and in my forum class I have decalred it in my global so the variable can be passed: $id = $forum_data['id']; $load->userDetails('db_topics', 't_forum_id', ':id', 't_whenlast', 'DESC'); $coll=$sth->fetch(PDO::FETCH_ASSOC); $this->html->RightForum($coll); The code is very silly, but the fact is I did not know how to do this.. Please help me put this query into a function because I need to make use of it in many other parts of the forum and I don't want to constantly declare this query.
-
Firstly, thank you soo much because my head was hurting like never before. I am sure I tried that.. I don't know I am sure.. I did realise an three hours ago the column passwords was the problem. I did not know how to solve it. However I think I get it now.. Thanks alot once again.
-
Hello, I am learning PDO SQL statements, I have mananged to connect using PDO: try { $this->link = $dbh = new PDO('mysql:host='.$this->dbhost.';dbname='.$this->dbname.'', $this->dbuser, $this->dbpass); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } I am not getting any error, so I guess that is a good start. I then tried the PDO SQL statement out. My old mySQL query is commented out in there: if (isset($_SESSION['id']) && isset($_SESSION['password'])) { $_SESSION['id'] = ( isset( $_SESSION['id'] ) ) ? $_SESSION['id'] : FALSE; $_SESSION['password'] = ( isset( $_SESSION['password'] ) ) ? $_SESSION['password'] : FALSE; //$logged = mysql_query("SELECT * FROM `db_members` WHERE `id`='".$_SESSION['id']."' AND `password` = '".$_SESSION['password']."'"); //$logged = mysql_fetch_array( $logged ); // the new pdo statement $ff = $dbh->prepare('SELECT * FROM db_members WHERE id = '.$_SESSION['id'].' AND password = '.$_SESSION['password'].''); $ff->execute(); $logged = $ff->fetchAll(); echo $logged['username']; } I am trying to assign the session to logged variable. So all I am asking is go into db_members and check the id and password that is the same as session id and password and collect the rows data such as username. My login script and everything works perfectly, even session id and password is valid when echo'd but I cannot assign it to the logged variable like my old sql statements. $logged = mysql_query("SELECT * FROM `db_members` WHERE `id`='".$_SESSION['id']."' AND `password` = '".$_SESSION['password']."'"); $logged = mysql_fetch_array( $logged ); I used other PDO statements and it works perfectly but I just don't understand why this is not working.... can I please get some help if you have any solution to this?
-
I see what you saying, can you please show or explain an example? I am just cannot fully understand. :< I have a dates colum in my forumm, at this moment I was just testing it and it is vanchar 30. All my dates are stored as: // Prints something like: Monday 8th of August 2005 03:12:46 PM echo date('l jS \of F Y h:i:s A'); so all my dates are like the printed example above echo. This is just a default time/date I have no date_default_timezone_set.
-
Hey, I have just recently coded a forum and my topics are ordered by date. This means if there is a topic at 4pm and then there is another topic made at 4:01pm the topic which was posted at 4:01pm will be listed at the top. I know how to add timezones but there is bit of a problem, if person from the UK posts a topic and his/hers timezone is set to: date_default_timezone_set('Europe/London'); this means the time at which the topic was posted will be 20:36pm (Just a randome time example). However if someone posted a topic from america/los_angeles one hour before the one above his/her time will be 11:36 am. Even though this topic was posted one hour before the UK post. The UK topic will override it because it is 8:36pm. In fact, all UK topics will show up at the top and all the america/los_angeles topics will show bellow. How do I slove this problem? I just don't get it even tough I looked online. Please help, thanks.
-
Hey, I am going to code a forum in PHP. I am not exactly aware of secuity measures, the only thing I know is to use POST form submission. Is there anything else that I need to be aware of? Please help, thank you.
-
I have been away from PHP for a long time and I was looking over my old scripts. I did PHP OOP at one time and I used a paticular method to connect all my methods up and load them. I have been looking at other peoples code and when I look at my code it does not even feel like OOP, I want to know how to you link all the methods (or is it called functions?) in a class up and return them? I use to do this: <?php class quickFUNC { function note_pad() { // code for notepad } function quickAdminFunc() { // code for admin func $this->note_pad(); } } $quickFUNC = new quickFUNC; if(isset($_GET['id'])) { $act = $_GET['id']; } else { $act = NULL; } switch ($act) { case 1: //some random code to launch case 1 break; default: $quickFUNC ->quickAdminFunc(); ?> This was my code back in the days, as you can see the notepad was called in the admin function then made the admin function default in the case switch. I looked at all my script and the all are layed out like this :S.. Can I get some help please, thank you.