Jump to content

Skatecrazy1

Members
  • Posts

    126
  • Joined

  • Last visited

Contact Methods

  • AIM
    skatecrzy1
  • MSN
  • Website URL
    http://www.snapskate.com/
  • Yahoo
    verrizzzon

Profile Information

  • Gender
    Male
  • Location
    Southern California

Skatecrazy1's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm used to OOP, but haven't used it much with PHP so the syntax and declarations are a bit hazy. Used it more often with C++ and Java, and whatever bastardized version of C++ arduino runs off of. I have used mysqli in the past so I do know that there are a few things that are different, how it takes arguments, etc. I am trying to get a basic grasp back on OOP syntax and database querying with php after being gone from it for years working in an industrial occupation. Currently rewriting my code with more updated syntax and function libraries. Having issues declaring protected or public variables as they seem to go undefined when it comes time to call them. Now bear with me, declaring your own constructors wasn't really necessary back when I was at it, so I'm still trying to wrap my head around the concept of it. I seem to be failing pretty hard. This code throws me an "UNEXPECTED T_VARIABLE" on line 6. <?php class Sql { protected $host, $user, $pass, $db; $host = "localhost"; $user = "admin"; $pass = ""; $db = "blog"; public function __construct($host, $user, $pass, $db){ $this->host = $host; $this->user = $user; $this->pass = $pass; $this->db = $db; $conn = mysqli_connect($host, $user, $pass); mysqli_select_db($db); } public function userData() { $sql = "SELECT * FROM users"; $result = mysqli_query($conn, $sql); $num = mysqli_num_rows($result); for($i = 0; $i < $num; $i++){ $data = mysqli_fetch_array($result); echo $data['name']; echo " | "; echo $data['email']; echo " | "; echo $data ['phone']; echo "<br />"; } } } ?>
  2. Is mysql improved expected to be supported for any length of time? It's closer to what I'm used to. The OOP is terrible because I used to write scripts back in the PHP2-3 days and never used objects with any frequency.
  3. Guess not. Was using the older code because that's what I remember off the top of my head. I'll seek help elsewhere, then. So long phpfreaks, you used to be cool.
  4. Thanks for making my point for me. I'm using it because I haven't written any code in a few years. Anyone on this forum who actually wants to look at my code ? Or has there been a large influx of pompous twits in the couple years I've been gone and no one actually helps out here anymore?
  5. Can you actually elaborate? What parts of my code are obsolete? Try being helpful instead of just confirming what I already know. For what it's worth the code was working perfectly fine until I imported everything into the new db.
  6. So I'm just starting this little side project to mess around with the idea of a torrent tracker site. I'm a little rusty with my hand-typed scripts so I'm sure I'm looking right at something here and missing it. Just trying to display table data from 'users'. Worked just fine while I ran it on the test db, but after exporting it from the test db and importing it into the actual db I'm using I get a boolean returned for my $result, which causes my num_rows to fail and throw an error. Thanks in advance for any help. <?php class Sql { public function __construct(){ global $host, $user, $pass, $db, $conn; $host = "localhost"; $user = "admin"; $pass = ""; $db = "blog"; $conn = mysql_connect($host, $user, $pass); mysql_select_db($db); } } class Connect extends Sql { //connect function and verification public function init(){ //this function connects to the database based on //global variables defined in the "Sql" class // globals global $user, $pass, $conn, $host, $db; if(!$conn){ print "Connection failed."; } else { print "<div id = \"connect\">"; print "SQL Connection Successful"; print "</div>"; } } } class Display extends Sql { //this class selects and displays data from a given table public function user_display(){ // globals global $conn; $sql = "SELECT * FROM users"; $result = mysql_query($sql, $conn); if(!$result){ echo $result; } $num = mysql_num_rows($result); echo " <table padding=\"3\" border=\"1\"> <tr> <td> <strong>Name</strong> </td> <td> <strong>Email</strong> </td> <td> <strong>Phone</strong> </td> </tr>"; //loop through the data for($i = 0; $i < $num; $i++){ $data = mysql_fetch_array($result); echo " <tr> <td> ".$data['name']." </td> <td> ".$data['email']." </td> <td> ".$data['phone']." </td> </tr>"; } mysql_close($conn); } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.