I have 2 files: apix.php and crud.php. I am trying to convert the fetched data from php to a jason print. The issue is that the function does not the results for me to parse in the next section of my code. The CRUD.php: class crud { private $db; function __construct($DB_con) { $this->db = $DB_con; } public function dataview_new($query) { $stmt = $this->db->prepare($query); $stmt->execute(); $users = array(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)){ array_push($users, $row); } return $users; } } the APIX.php: require_once 'crud.php'; $crud = new crud($DB_con); $res = array('error' => false); $action = 'read'; if(isset($_GET['action'])){ $action = $_GET['action']; } if($action == …

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I wonder if you can help. As I've started as a programmer, I've been told I have to practice OO a bit more. I've done the theory, but I think I will have to take another look at it. , Above all though, I have to do exercises. What I'm looking for is for suggestions: things I have to practice are: -Inheritance -Interfaces -Polymorphism -And in general anything to do with OO. Ideally I don't really need to do any complicated exercise, even simple scenarios would do as long as I can put into practice the theory, printing …

Member Avatar
Member Avatar
+1 forum 3

Normally you can do this and pass the reference type by reference and the new keyword won't make the variables point to different objects: static void Main(string[] args) { Object origObj = new Object(); ExampleMethod(ref origObj); } void ExampleMethod(ref Object newObj) { //origObj will also reference the newly created object with the following line. origObj and newObj will point to the same object. newObj = new Object(); } I'd like to do this, without using a method to do it: static void Main(string[] args) { Object origObj = new Object(); Object newObj; // something that would mean the same as …

Member Avatar
Member Avatar
+0 forum 3

Here is what i have to do Create Class CSalary with private member variables string m_strProfession double m_dSalary Constructors:Default,Copy,Explicit Functions: 1/string GetProf(void),double GetSalary(void) 2/SetProf(const string val),SetSalary(const double val) 3/Output(ostream&) and Input(istram&) 4/Operators:<<,>>,=,==,<,double operator*(const CSalary&obj) Create Class CCalcCorr with private member variables: vector<CSalary>m_vCity1//data for city 1 vector<CSalary>m_vCity2//data for city 2 double m_dCorr//correlation coefficient Constructors: Explicit by data filenames string fNmae1,string fName2 CCalcCorr(const string& strFileName1,const string& strFileName2) <profession> <salary> Web Developer 5000 Functions:/I want help for these functions/ Colculate correlation coefficient btw 2 vectors in m_dCorr and return it in dCorr.Return false if can't calculate Formulas: Corr=SUMxy/sqrt(SUMxxSUMyy) where : SUMxx = SUM(City1City1)-SUM(City1)SUM(City1)/n …

Member Avatar
Member Avatar
+0 forum 1

First off, here is the code I will be referencing: package com.airamerica.dataConversion; import com.airamerica.Airports; import com.airamerica.Person; import com.airamerica.Products.Products; import com.airamerica.Products.Tickets; public class FindObject { public static Airports findAirport(String airportCode, Airports [] airportsArray){ Airports airport = null; for(int j = 0; j < airportsArray.length; j++) { if (airportCode.equals(airportsArray[j].getCode())){ airport = airportsArray[j]; break; } } return airport; } public static Tickets findTicket(String productCode, Products[] productArray){ Tickets product= null; String matchCode = null; for(int j = 0; j < productArray.length; j++) { matchCode = productArray[j].getCode(); if (matchCode.equals(productCode)){ product = (Tickets) productArray[j]; break; } } return product; } public static Person findPerson(String personCode, Person[] …

Member Avatar
Member Avatar
+0 forum 1

Hi I am trying to create a update function. But it not updating in the database. Please help me to fix. **Test-2.php** $whereString = ''; $bind = NULL; if(isset($_POST['Submit'])) { if($_POST) { $SCYQ64UKID = $_GET['SCYQ64UKID']; $SCYQ64AVGP = $_POST['SCYQ64AVGP']*100; $searchFields = array('SCYQ64EMAL'=>$_POST['SCYQ64EMAL'],'SCYQ64EV01'=>$_POST['SCYQ64EV01'],'SCYQ64EV02'=>$_POST['SCYQ64EV02'],'SCYQ64EV03'=>$_POST['SCYQ64EV03'],'SCYQ64EV04'=>$_POST['SCYQ64EV04'],'SCYQ64EV05'=>$_POST['SCYQ64EV05'],'SCYQ64EV06'=>$_POST['SCYQ64EV06'],'SCUSER'=>$_POST['SCUSER'],'SCYQ64AVGP'=>$SCYQ64AVGP,'SCYQ64TZ'=>$_POST['SCYQ64TZ'],'SCJOBN'=>gethostname(),'SCPID'=>'SSWEB','SCUPMJ'=>$_POST['SCUPMJ'],'SCUPMT'=>$_POST['SCUPMT']); if($post = array_filter($_POST)) { if($fields = array_intersect_key($searchFields, $post)) { $where = array(); $bind = array(); foreach($fields as $key=>$field) { $where[] = "$key LIKE '%$field%'"; $bind[":$key"] = $_POST[$key]; $gwhere[] = "$key=$field"; $gbind[":$key"] = $_POST[$key]; } //$whereString = ' WHERE ' . implode(' AND ', $where); $gwhereString = implode(',', $gwhere); } $Users = new Users($db); $query = $Users->smipleUpdate('FQ64000',$gwhereString,'SCYQ64UKID='.$SCYQ64UKID); } } } …

Member Avatar
Member Avatar
+0 forum 12

Hi I am trying to display count of a row using function with get values. Please help me to fix the issue **class** class Users { private $conn; private $db_name= "DATABASE"; public function __construct($db) { $this->conn = $db; } /*Join Two Tables with where condition and order by*/ public function getJoinRows($tablen1,$tablen2,$where,$order_by){ $query = $this->conn->prepare("select * FROM $this->db_name.$tablen1,$this->db_name.$tablen2 where $where ORDER BY $order_by DESC"); try { $query->execute(); return $query; }catch(PDOException $e) { die($e->getMessage()); } } /**/ public function transCount($tablen,$whereCondition) { $query = $this->conn->prepare("select count(*) from $this->db_name.$tablen where $whereCondition"); try{ $query->execute(); return $row_count = $query->fetchAll(); }catch(PDOException $e) { die($e->getMessage()); } } } …

Member Avatar
Member Avatar
+0 forum 5

I have created a function. if i provide correct username and password. i am getting a error message as **Sorry, that username / password is invalid !** can any one please help me to fix the issue. **login.php** <?php require 'include/init.php'; $general->logged_in_protect(); if(empty($_POST) === false) { $username = trim($_POST['username']); $password = trim($_POST['password']); if(empty($username)===true || empty($password)=== true) { $errors[] = 'Sorry, But we need your username and passowrd.'; } else { $login = $users->login($username, $password); if($login === false) { $errors[] = 'Sorry, that username / password is invalid'; } else { $_SESSION['user_'] = $login; header('Location: dashboard.php'); exit(); } } } ?> …

Member Avatar
Member Avatar
+0 forum 3

Hi I am trying to connection my database ODBC using function. I am getting an error **Connection error: could not find driver** **mycode is** <?php class Database{ // specify your own database credentials private $host = "servername"; private $db_name = "databsename.schemaname"; private $username = "username"; private $password = "password"; public $conn; // get the database connection public function getConnection(){ $this->conn = null; try{ $this->conn = new PDO("odbc:host=" . $this->host . ";dbname=" . $this->db_name, $this->username, $this->password); }catch(PDOException $exception){ echo "Connection error: " . $exception->getMessage(); } return $this->conn; } } ?> Please help me to fix the issue.

Member Avatar
Member Avatar
+0 forum 12

Hi, Reading CodeIgnitier documentation I saw some statements having this form: $this->someword->somefunction(); and I don't know what is that. Is someword an multi-dimensional/associative array? I know that if I create an instance of a class I can access its properties and functions with a single -> operator or with :: operator. But I don't know what means usage of 2 -> parameters. Thanks!

Member Avatar
Member Avatar
+0 forum 1

Hi all, I've been working with PHP, using procedural methods, for several years now, and have begun to explore the object-oriented side of it. While it didn't take me long to understand the potential advantages that come with working in this manner, I'm still having some trouble wrapping my head around doing the things I used to do procedurally in an object-oriented manner. A lot of the tutorials cover the basic applications of classes, properties, and methods, but I'm having trouble applying them to projects I'm working on. For instance, I have a form, that I put a class together …

Member Avatar
Member Avatar
+0 forum 15

Hello everyone. I am currently making some database connection modules in Python inb order to learn Python's approach to OOP and also to lear how to connect to databases via Python. I successfully made a package with modules for postgres, mysql, sqlite3, and MongoDB. The classes simply connect, disconnect and run queries of any type. Everything is working fine now. However I noticed that the code is nearly the same. For example, the connect and disconnect methods are exactly the same. Also, postgress and mysql connections have exactly the same number of attributes. Inheritance came to mind, but some classes …

Member Avatar
Member Avatar
+0 forum 16

Greetings, I'm having problems with my output. Essentially I am just trying to print out any Cat who is over 3 years old and has Claws. But my output keeps printing out either nothing at all or the 3rd cat 3 times. I've struggled with this for hours trying to figure out why.. any ideas? This is my driver java file. It will compile and run just fine but it doesn't work like it is supposed to.. import java.util.Scanner; public class NathanialProg6 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Cat cat1 = new Cat(); Cat …

Member Avatar
Member Avatar
+0 forum 3

I'm trying to write a boolean function that takes two Mytime objects, t1 and t2 as arguments, and returns True if the object falls inbetween the two times. This is a question from the How to Think Like a Computer Scientist book, and I need help. What I've gotten so far: class MyTime: def __init__(self, hrs=0, mins=0, secs=0): self.hours = hrs self.minutes = mins self.seconds = secs def between(t1, t2): if t1 <= t2: return True else: return False I just don't understand how to make a function that uses MyTime objects into the boolean function? Any help would be …

Member Avatar
Member Avatar
+0 forum 4

please tell me in how many ways OBJECT ORIENTED PROGRAMMING is different from procedural programming in JAVA

Member Avatar
Member Avatar
+0 forum 6

I can't seem to get a response from my query method. I have a database connection from method ping_server and use mysqli as connector. Can anyone help me figure out why I cannot print results from mysqli_fetch_array. dbclass.php class db { private $connection; private $selectdb; private $lastQuery; private $config; function __construct($config) { $this->dbConfig = $config; } function __destruct() { } public function openConn() { try { if($this->dbConfig->connector == "mysqli") { $this->connection = mysqli_connect($this->dbConfig->hostname, $this->dbConfig->username, $this->dbConfig->password); $this->selectdb = mysqli_select_db($this->dbConfig->database,$this->connection); } } catch(exception $e) { echo'Caught Exception:', $e->getMessage(), "\n"; } } public function closeConn() { try { if($this->dbConfig->connector == "mysqli") { mysqli_close($this->connection); …

Member Avatar
Member Avatar
+0 forum 4

I'm trying to modify this code to take advantage of classes and some other oop features. However, I'm struggling with getting beyond the basics. This is the code that I started with which I am trying to change and make more class absed. import glob import os import sys print(os.getcwd()) dir= raw_input(["Please enter directory location of dcp_inspect output"]) print (dir) os.chdir(dir) print(os.getcwd()) cpl = [] content = [] errors = [] contentkind = [] summary = [] for file in glob.glob("*"): try: print (file,'\t Was Successfully Opened') #file = DcpParse() newfile = file print('Scanning...', newfile) data = open(newfile) for each_line …

Member Avatar
+0 forum 0

Hi guys, Tomorrow is my theory paper exam of C++ OOP and Data Strucutre. Paper will be based on 50% theory Q/A and 50% on coding implentaion. Can you give me some hints to prepare for this coming exam? PS. I have gone throw all lectures slides and course material, but you know what I am asking for, how can I prepare my se;f to do 100% job? Thanks, Regards, Umer Jamil.

Member Avatar
Member Avatar
+0 forum 1

hlo all, i need to write a code in php oop for registration without using form and data directly goes in the database. i try to write the code for this. i show u that code and help me to correct that or by giving me another code. the database name is # *bhumi_regn* # and there is an error " # Fatal error # : Call to a member function prepare() on a non-object in C:\wamp\www\bhumi regn\ADAO.php on line 20" thanks `ADAO.php` <?php include 'connect.php'; class ADAO { public static function registerUsers($users,$dbh){ try { } catch (PDOException $e) { …

Member Avatar
Member Avatar
+0 forum 6

This started out as `I love PHP traits! I'm going to use them everywhere! ^_^` and now it has turned into a `Thought Exercise / Learning Experience >_<`. Consider the following example: trait TheErrorOfYourWays{ public function booboo(){ echo 'You had a booboo :('; } } trait SpectacularStuff1 { use TheErrorOfYourWays; } trait SpectacularStuff2 { use TheErrorOfYourWays; } class DoSomethingSpectacular { use SpectacularStuff1, SpectacularStuff2; } This results in (obviously): > Fatal error: Trait method booboo has not been applied, because there are collisions with other trait methods on DoSomethingSpectacular. **So my question: How do I resolve method conflicts in traits? Is …

Member Avatar
Member Avatar
+2 forum 6

Having just found 'traits' - see http://www.daniweb.com/web-development/php/threads/468928/php-trait-method-conflicts-trait-inheritance#post2043565 I was wondering whether they could be used to share a DB connection object across disparate classes, or would the old singleton or dependency injection methods still be the way to go? I'd value any views on this.

Member Avatar
Member Avatar
+2 forum 2

Hi All, I am trying to add insert/update and delete to an OOP singleton database connection using public functions like this, not sure if it is correct? example code public function insert($sql){ if($this->_execute= $this->_mysqli->_execute($sql)){ while ($row = $this->_execute->fetch_object()){ $this->_results[] = $row; } $this->_count = $this->_execute->num_rows; } return $this; } //page index.php <?php require_once 'classes/db.php'; function Users(){ $users = DB::getInstance()->query('SELECT UserID, UserFullName, UserEmail, UserLastPassword, UserName, UserActive FROM Users'); if ($users->count()){ foreach ($users->results() as $user){ echo $user->UserName, $user->UserActive,$user->UserLastPassword,'<br />'; } } } Users(); //page db.php <?php class DB { private $_mysqli, $_query, $_results = array(), $_count=0, $_last_id = -1; public static $instance; …

Member Avatar
Member Avatar
+0 forum 17

Hi All, I am trying to connect to a database OOP singleton method. I am getting an error "syntax error, unexpected 'function_construct'" and I unable to find the syntax error in the code. Any help with this would be appreciated. Thanks in advance David // Page: index.php <?php require_once 'classes/db.php'; echo '<pre>', print_r(DB::getInstance()->query('SELECT * FROM Users')->results()), '</pre>'; //classes/db.php <?php //classes/db.php class DB { private $_mysqli, $_query, $_results = array(), $_count=0; public static $instance; public static function getInstance(){ if (isset(self::$instance)){ self::$instance = new DB(); } return self::$instance; } public function_construct(){ $this->_mysqli = new mysqli('localhost','xxxx','xxxxx','db301847341'); if($this->_mysqli->connect_error) { die($this->_mysqli->connect_error); } } public function …

Member Avatar
Member Avatar
+0 forum 5

please can you help me to solve this problem :>>> no develop a bookstore information system. The bookstore manages a collection of books it is selling, book orders, and customers who purchased from the store. A book store also has a counter that accepts cash from book sales. Each book Customer can search for a book by its ID, title, author, publisher, edition, year of publication and price. The book store also records the number of copies available for each book. Customers can order a book from the bookstore. The bookstore needs to keep information about its customers such as …

Member Avatar
Member Avatar
+0 forum 6

I'm having hard times, learning desing patterns. And, I've been reading quite a lot. But, I'm only interested to know, about two things: Adapter & Factory patterns. From what I undestood, (*which is close to nothing*) Factory Pattern helps create objects on the fly Adapter Pattern helps adapt your class from changes made externally. That is the only thing I undetood. Which is why, I am looking for simples possible, practical examples on either both if possible. on how to use them. So, I am providing just, two simple classes, only to help any demostrate the purpose of the two …

Member Avatar
Member Avatar
+0 forum 1

I would like some help with my connect class.This class is created by me it is my way of thinking so i would like to know why this class dossent get my variables and connect proprely to mysql. the code <?php /** * Exp:Connect to database in oop style @params host dbname username password */ class Connect { //private only available forthe current class private $host=null; private $dbname = null; private $username = null; private $password = null; function __construct($host,$dbname,$username,$password) { $this->host = $host; $this->dbname = $dbname; $this->username = $username; $this->password = $password; $host = "localhost"; $dbname = "testoop"; $username …

Member Avatar
Member Avatar
+0 forum 6

Hy I want to understand what is a better approach on problem solving point of view for a php project , a framework or the mvc pattern? I would like to add that I know that both principels are quite the same but with a minor diffrence that a framework was made by someone else and has his style applied to it and a mvc pattern you build your own classes and templates and create it in your own style. My concern regarding the mvc pattern is that a application build from scartch is harder to do and create a …

Member Avatar
Member Avatar
+0 forum 5

I would like to know, why extending a built-in class in php is important. I mean let's take the PDO class for example. One can either work with using new PDO(); or class Foo extends PDO. to do the same task. I guess, maybe the only thing that makes sense here is, that if I extend the class, there may be less overhead during the scripts run time, because I am working from something within the class, and I may be able to work with public, protects methods and properties, and also add more of those, but that is as …

Member Avatar
Member Avatar
+0 forum 19

today a friend told me that Hunain, did you notice that OOP concepts like inhertance, polymorphism, interface etc aren't usuallt applied to ASP.net. so it made me confused and thought for a while, and yes he seems to be right ! i never used any of them adn even most complex asp.net developers never did, among my teachers or friends, is it so ?

Member Avatar
Member Avatar
+0 forum 3

Hi all, I've literally JUST dived into OOP and it's a totally different world. I've written some pretty awful code just to grasp OOP basics. The following code is all in the same file and runes fine, there are no warnings, errors, notices and so forth yet it doesn't work correctly... I think it's something dead simple and if it is I promise to facepalm as hard as I can. Thanks for any help in advance. # Code: # <?php error_reporting(E_ALL); class database{ protected $_link, $_result, $_numRows; public function __construct(){ $this->_link = mysqli_connect('localhost', 'root', '', 'studybubble') or die(mysqli_error()); } public …

Member Avatar
Member Avatar
+0 forum 11

The End.