Difference between "->" and "::" in PHP MySQLi OOP

Asked
Active3 hr before
Viewed126 times

7 Answers

difference
90%

Can anyone tell the difference between mysqli->commit and mysqli::commit?,:: accesses the class' function without instancing an object., Is ad-hoc polymorphism a good practice in functional programming? , Jobs Programming & related technical career opportunities

Consider the following class:

class FooBar {
   public static
   function fizz() {
      echo "Fizz";
   }

   public
   function buzz() {
      echo "Buzz";
   }
}

You would call the function buzz() using ->:

$myFooBar = new FooBar();
$myFooBar - > buzz();

But would use :: to call the functon fizz(), as it is a static member (a member which doesn't require an instance of the class to be called):

FooBar::fizz();

The documentation uses :: to refer to a function inside a class as the class name in the header is not an instance of the class. Still using the same example, a documentation entry referring to the function buzz() would use the following header:

FooBar::buzz

But unless the documentation specifies it's a static member, you will need to use -> on an instance to call it:

$myFooBar = new FooBar();
$myFooBar - > buzz();
load more v
88%

Can anyone tell the difference between mysqli->commit and mysqli::commit?

Consider the following class:

class FooBar {
   public static
   function fizz() {
      echo "Fizz";
   }

   public
   function buzz() {
      echo "Buzz";
   }
}
load more v
72%

There are no significant performance differences between the two interfaces. Users can base their choice on personal preference. , The mysqli extension features a dual interface. It supports the procedural and object-oriented programming paradigm. ,Example #1 Easy migration from the old mysql extension, The object-oriented interface is used for the quickstart because the reference section is organized that way.

Please do not use the deprecated mysql extension
for
new development.Use the mysqli extension instead.
load more v
65%

PDOStatement::fetchAll(): It returns the result in the form of an array, containing all of the result rows.,PDOStatement::setFetchMode(): It sets the default fetch mode for the statement.,PDOStatement::fetchColumn(): It fetches a single column from the next row of a result set.,PDOStatement::fetchObject(): This first fetches the next rows and then returns it as an object.

75%

:: is the Scope Resolution Operator and is used to refer to a static member of a Class.,Consider the following class:,-> is used when referring to a member of an object.,But would use :: to call the functon fizz(), as it is a static member (a member which doesn't require an instance of the class to be called):

Consider the following class:

class FooBar {
   public static
   function fizz() {
      echo "Fizz";
   }

   public
   function buzz() {
      echo "Buzz";
   }
}

You would call the function buzz() using ->:

$myFooBar = new FooBar();
$myFooBar - > buzz();

But would use :: to call the functon fizz(), as it is a static member (a member which doesn't require an instance of the class to be called):

FooBar::fizz();

The documentation uses :: to refer to a function inside a class as the class name in the header is not an instance of the class. Still using the same example, a documentation entry referring to the function buzz() would use the following header:

FooBar::buzz

But unless the documentation specifies it's a static member, you will need to use -> on an instance to call it:

$myFooBar = new FooBar();
$myFooBar - > buzz();
load more v
40%

Application Source Code from the Previous Lesson,The current document is a part of the Creating a CRUD Application in the NetBeans IDE for PHP tutorial.,Application Source Code after the Current Lesson Is Completed,MySQL users: Click here to download the source code that reflects the project state after the previous lesson is completed.

class WishDB extends mysqli {

   // single instance of self shared among all instances
   private static $instance = null;

   // db connection config vars
   private $user = "phpuser";
   private $pass = "phpuserpw";
   private $dbName = "wishlist";
   private $dbHost = "localhost";

}
load more v
22%

“mysqli_select_db(…)” is the database selection function that returns either true or false,The mysqli_select_db function is used to select a database., “mysqli_connect(…)” is the function for php database connection, “mysqli_query(…)” is the function that executes the SQL queries.

It has the following syntax.

< ? php;
$db_handle = mysqli_connect($db_server_name, $db_user_name, $db_password); ?
>
load more v

Other "difference-undefined" queries related to "Difference between "->" and "::" in PHP MySQLi OOP"