Planet MySQL Planet MySQL: Meta Deutsch Español Français Italiano 日本語 Русский Português 中文
Showing entries 1 to 6

Displaying posts with tag: pdo (reset)

Handling SQL Errors in PDO
+0 Vote Up -0Vote Down

I love PHP's PDO (PHP Data Objects) extension; it gives a consistent, object-oriented interface to handling all kinds of relational database backends. One thing that annoys me is that the MySQL driver for PDO defaults to a silent error mode which can make SQL errors tricky to spot!

To give you an example, consider the query below (the correct tablename is country, so this SQL will fail):

$db = new PDO('mysql:host=localhost;dbname=sakila', 'user', 'pass');
 
$sql = 'select * from countrt';
$stmt = $db->query($sql);
 
while(($row = $stmt->fetch()) != false) {
    echo $row['country'] . "\n";
}

The script will output an error because $stmt is not an object.

You have a few options here - you can check that you got

  [Read more...]
Scalar type hints in PHP trunk
Employee +1 Vote Up -2Vote Down

So in my blog series I try to cover all additions to PHP trunk so I have to mention scalar type hints.

<?php
function print_float(float $f) {
    echo $f."\n";
}

for ($i = 1; $i < 5; $i++) {
    print_float( $i / 3 );
}
?>
	
0.33333333333333
0.66666666666667

Catchable fatal error: Argument 1 passed to print_float() must be of the type double, integer given, called in typehints.php on line 7 and defined in typehints.php on line 2

Is expected behavior in PHP's trunk. If you want such a thing to work please use the numeric type hint.

In case that wasn't enought fun: There's more!

<?php
function handle_result(int $i) {
    echo $i."\n";
}



  [Read more...]
Jumpstarting PDO
+1 Vote Up -1Vote Down

Lukas is making another attempt at jumpstarting PDO development.  I welcome this effort, and will do what I can to help fill in details and make suggestions.  Unfortunately, I'm just way too busy with work to be able to commit to more than that.

I also wanted to share some of my thoughts on why PDO has been in a holding pattern for a while, so that more people are aware of it and can work to avoid repeating the same mistakes.

The first thing to note is that the guts of PDO were hard to develop.  The PHP script facing API sounds simple enough, but the underlying libraries for each different databases work in different ways, and it was and is a challenge to build PDO in such a way that it can work in the most efficient way.

The second thing, which is really a follow-on from the first, is that the database

  [Read more...]
Developing MySQL Database Applications With PHP
Employee +1 Vote Up -0Vote Down

A four part tutorial that explains the PHP / MySQL extensions - mysql, mysqli, and pdo_mysql - with simple examples is now accessible from Sun Developer Network. While most of the information presented in the tutorial is available elsewhere in bits and pieces, the real value-add is in the introduction of the MySQL native driver for PHP, mysqlnd.

Here is a brief description of all four parts in the series. Check them out, and as always feel free to send the corrections, comments, suggestions, etc., to my Sun mail ID: Giri.Mandalika@Sun.COM

  [Read more...]
Developing MySQL Database Applications With PHP
Employee +0 Vote Up -0Vote Down

A four part tutorial that explains the PHP / MySQL extensions - mysql, mysqli, and pdo_mysql - with simple examples is now accessible from Sun Developer Network. While most of the information presented in the tutorial is available elsewhere in bits and pieces, the real value-add is in the introduction of the MySQL native driver for PHP, mysqlnd.

Here is a brief description of all four parts in the series. Check them out, and as always feel free to send the corrections, comments, suggestions, etc., to my Sun mail ID: Giri.Mandalika@Sun.COM

  [Read more...]
Developing MySQL Database Applications With PHP
Employee +0 Vote Up -0Vote Down

A four part tutorial that explains the PHP / MySQL extensions - mysql, mysqli, and pdo_mysql - with simple examples is now accessible from Sun Developer Network. While most of the information presented in the tutorial is available elsewhere in bits and pieces, the real value-add is in the introduction of the MySQL native driver for PHP, mysqlnd.

Here is a brief description of all four parts in the series. Check them out, and as always feel free to send the corrections, comments, suggestions, etc., to my Sun mail ID: Giri.Mandalika@Sun.COM

  [Read more...]
Showing entries 1 to 6

Planet MySQL © 1995, 2014, Oracle Corporation and/or its affiliates   Legal Policies | Your Privacy Rights | Terms of Use

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.