|
Posted by Andy Hassall on 12/17/05 14:07
On Sat, 17 Dec 2005 12:09:55 +0100, "Ben" <qsvqs@qsdcsqd> wrote:
>I started with php and mysql and i discovered three methods for connecting
>to a database:
>
>$conn="DRIVER={MySQL ODBC 3.51 DRIVER};SERVER=10.0.0.181;DATABASE=reserv";
> $connect=odbc_connect($conn,'root','pw');
ODBC. Used a lot on ASP, not so much in PHP, as PHP has native database
libraries (including MySQL).
>include('/inetpub/wwwroot/resphpaccess/adodb/adodb.inc.php');
>$db = &ADONewConnection('mysql');
>$db->Connect('localhost', 'root', 'pw', 'reserv');
ADOdb database abstraction library (http://adodb.sourceforge.net), a thin PHP
wrapper over the native functions.
This is my favourite way of connecting to databases in PHP. It adds a
consistent interface on top of the different native calls, and supports several
databases (not just MySQL).
Importantly for MySQL it emulates placeholders, which makes it easier to avoid
SQL injection attacks.
There is some overhead versus accessing MySQL with the native functions
directly, but ADOdb fares well in benchmarks, particularly compared with other
PHP database libraries.
>$link = mysql_connect("localhost", "mysql_user", "mysql_password")
> or die("Impossible de se connecter : " . mysql_error());
Native MySQL library. The thinnest layer over MySQL, so presumably the fastest
performance. You'll have to remember to do all your own data escaping, else you
open yourself up to SQL injection attacks.
--
Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Navigation:
[Reply to this message]
|