Jump to content

BlazeMike

New Members
  • Posts

    3
  • Joined

  • Last visited

BlazeMike's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. by the way i have a question. I have developed some web applications in the past based on old mysql functioning. If i was asked to make changes or aditions to that code should i migrate ALL the code to PDO or should i just make the requested changes in Mysql?
  2. Thanks for your replies. Hmm ok i will study PDO, seems to be a must! by the way PDO is just for databases, answeing my initial post will help me understand classes/functions in general! I cannot use class->fuction->function? im ive seen scripts using that :|
  3. Hi everyone, Until now i didnt use classes and functions for sql related actions and now i would like to start. I started out with this : class.php --------------------------------------------------- class db { public function connect($database,$user,$password) { $db = mysql_connect("localhost",$user,$password) or die (mysql_error()); mysql_select_db($database); } static function fetch() { function getresults($query) { $resultArray = array(); $fetch = mysql_query($query) or die (mysql_error()); while ($row = mysql_fetch_assoc($fetch)){ $resultArray[] = $row; } return $resultArray; mysql_free_result($fetch); } } } and index.php ---------------------------- <?php require('class.php'); $connection = new db(); $connection->connect("testdb","root","root"); $connection->fetch()->getresults("SELECT * FROM users"); foreach (getresults() as $user) { echo "<div>{$user['user_first_name']}</div>"; } BUt it doesnt work. Actually the only way it works is : $connection::fetch(); foreach (getresults("SELECT * FROM users") as $user) { echo "<div>{$user['user_first_name']}</div>"; } Now my ultimate goal is : - I want to access db and get results anyware in my script to use : $connection->fetch("SQL QUERY"); and then foreach to echo the results. - I want to put more functions in fetch. For example if i want to fetch number of results to use $connection->fetch()->results(); Im sorry if i confused you! Basically i want to make everything tidy but im not familiar with the logic. I know basic class/function use. Thanks in advance
×
×
  • 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.