Skip to content

berry.mysql.MySQLConnection

Nikos Siatras edited this page Sep 30, 2022 · 14 revisions

Definition

MySQLConnection class represents a connection to a MySQL Server database.

 public function __construct($serverIP, $database, $user, $password, $charset = "")

Examples

Establish a MySQL Connection

The following example establishes a new connection with the MySQL server, execute a simple query and then closes.

require_once(__DIR__ . "/berry/mysql.php"); // Include php-berry mysql package

// Establish a connection with MySQL server
$connection = new MySQLConnection('localhost', "database_name", "username", "password", 'utf8');

$query = "UPDATE students SET Grade=9 WHERE ID=4";
$command = new MySQLCommand($connection,$query);
$command->ExecuteQuery();

$connection->Close();