-
Notifications
You must be signed in to change notification settings - Fork 0
berry.mysql.MySQLConnection
Nikos Siatras edited this page Oct 1, 2022
·
14 revisions
public function __construct($serverIP, $database, $user, $password, $charset = "")
MySQLConnection class represents a connection to a MySQL Server database.
The following example creates a MySQLCommand and a MySQLConnection. The MySQLConnection is opened and set as the Connection for the MySQLCommand. The example then calls ExecuteQuery. To accomplish this, the ExecuteQuery is passed a MySQLConnection and a query string that is a Transact-SQL UPDATE statement. The connection is closed using the $connection->Close();
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);
$affectedRows = $command->ExecuteQuery(); // Execute query and keep number of affected rows
print "Affected rows: " . $affectedRows;
$connection->Close();