Friday, September 23, 2011

Workbench Scripts

A was checking out the new Workbench today after I saw this blog post http://wb.mysql.com/?p=1169

It all worked great and very easy.  Nice clean code that helps out the PHP Developer.
example:
$host="localhost";
$port=3306;
$socket="";
$user="";
$password="";
$dbname="";

$con = new mysqli($host, $user, $password, $dbname, $port, $socket)
    or die ('Could not connect to the database server' . mysqli_connect_error());

//$con->close();


$query = "SELECT * FROM exampledb";


if ($stmt = $con->prepare($query)) {
    $stmt->execute();
    $stmt->bind_result($field1, $field2);
    while ($stmt->fetch()) {
        //printf("%s, %s\n", $field1, $field2);
    }
    $stmt->close();
}

While this is a simple example it is a fantastic way for new developers to get started and learn how things are done.

A DBA can easily write a complex query and hand over PHP code to the developer. Nice work!

The ability to then write your own plugins really opens it up for some advanced developers. 

This is a step in the right direction and supports working together between DBA and developer.