Question

A table in MySQL names users has 3 String fields including firstname, lastname and username. Write...

A table in MySQL names users has 3 String fields including firstname, lastname and username. Write a complete PHP class that would allow for constructing a users object and getting and setting values for each of the fields

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource valid, or FALSE on error.

<?php

$firstname = 'fred';

$lastname  = 'fox';

$query = sprintf("SELECT firstname, lastname, address, age FROM friends
    WHERE firstname='%s' AND lastname='%s'",
    mysql_real_escape_string($firstname),
    mysql_real_escape_string($lastname));

$result = mysql_query($query);

if (!$result) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $query;
    die($message);
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row['firstname'];
    echo $row['lastname'];
    echo $row['address'];
    echo $row['age'];
}
mysql_free_result($result);
?>

PHP will internally create a new object from scratch ,execute __construct() in the Foo class, and assign this object to the variable $object.

class Foo {

    public function __construct() {

    }

}

class Bar extends Foo {

    public function __construct(ArrayObject $arrayObj, $number = 0) {

}

}

class Baz extends Bar {

    public function __construct(Bar $bar) {

}

}

Add a comment
Know the answer?
Add Answer to:
A table in MySQL names users has 3 String fields including firstname, lastname and username. Write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username an...

    Lab 4: Databased Admin Tool Continued Python Objective: In the previous lab, you developed an admin tool for username and password management. You accomplished the tasks with Dictionary or List. Here, use class to design your own data structure to accomplish a similar task. The UD.txt datafile: FIRST NAME, LAST NAME,USERNAME,PASSWORD Sam, DDal,sdd233,Pad231 Dave, Dcon,dcf987, BHYW4fw Dell, Grant,dgr803,Sb83d2d Mike, Kress,mkr212,UNNHS322 Lisa,Kate,lki065,dgw6234 Paul,Edward,ped332,9891ds Youyou,Tranten,ytr876,dsid21kk Nomi,Mhanken,nmh223,3282jd3d2 Write a program that imports the database from UD.txt, your program can search for users’ password....

  • I am creating a program that will allow users to sign in with a username and...

    I am creating a program that will allow users to sign in with a username and password. Their information is saved in a text file. The information in the text file is saved as such: Username Password I have created a method that will take the text file and convert into an array list. Once the username and password is found, it will be removed from the arraylist and will give the user an opportunity to sign in with a...

  • MySQL Practice Student StudentID FirstName LastName Street City State Zipcode 10001 Bruce Wayne 123 Elm Street...

    MySQL Practice Student StudentID FirstName LastName Street City State Zipcode 10001 Bruce Wayne 123 Elm Street Gotham City New York 10028 10002 Peter Parker 456 Corallville New York New York 10037 10003 Tony Stark 777 Faith Ave Malibu California 60263 School SchoolID SchoolName City State Zipcode 19837 Gotham High School Gotham City New York 10028 83649 Midtown High School New York New York 10037 73934 MIT Cambridge Massechusetts 02139 Attendee AttendeeID StudentID 100 10001 200 10002 300 10003 Attend AttendeeID...

  • ( Object array + input) Write a Java program to meet the following requirements: 1. Define...

    ( Object array + input) Write a Java program to meet the following requirements: 1. Define a class called Student which contains: 1.1 data fields: a. An integer data field contains student id b. Two String data fields named firstname and lastname c. A String data field contains student’s email address 1.2 methods: a. A no-arg constructor that will create a default student object. b. A constructor that creates a student with the specified student id, firstname, lastname and email_address...

  • In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class...

    In JAVA #3 Write a program named nameChanger.java. This program will only have a driver class with a main. This program will have the user enter a series of names(first and last), which will then be stored in a String array. You will then change the values of each of the names in the array, so that they are stored lastname, firstname, and then output the revised array. Sample: Enter a name (first and last): Tonya Pierce Enter a name...

  • Need a PHP code that has a box to type in that allows the user to...

    Need a PHP code that has a box to type in that allows the user to put the information through the PHP site to the database for the following categories: INT, First name, Last name, Sex. Once injected it needs to echo to the page to show the table of all entries. The code below is how far I got with it. MySQL: add a row and query $link = mysql_connect('stewcraw.dotstermysql.com', 'prof', '3632password'); if (!$link) { die('Could not connect: '...

  • We will build one Python application via which users can perform various analytics tasks on data...

    We will build one Python application via which users can perform various analytics tasks on data in 2-D table (similar to Spreadsheet) format which looks like: Column Name 1 Column Name 2 Column Name 3 Column Name N … … … … … In this table, each row represents the data of one object that we are interested in. Columns, on the other hand, represent the attributes of these objects. For example, this table could represent students’ academic records. Each...

  • Named TennisGame that holds data about a single tennis T he class has six fields: the names of th...

    java named TennisGame that holds data about a single tennis T he class has six fields: the names of the two players, the integer final tor the players, and the String values of the final scores. Include a get or each of the six fields. Also include a set method that accepts two names, and another set method that accepts the two integer final players re values. The integer final score for a player is the number of points the...

  • Java Program Write a class named Car that has the following fields: yearModel- The yearModel field...

    Java Program Write a class named Car that has the following fields: yearModel- The yearModel field is an int that holds the car’s year model. make- The make field is a String object that holds the make of the car, such as “Ford”, “Chevrolet”, etc. speed- This speed field is an int that holds the car’s current speed. In addition, the class should have the following methods: Constructor- The constructor should accept the car’s year model and make as arguments....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT