mysql-native: API Refresh RC

Nick Sabalausky via Digitalmars-d-announce digitalmars-d-announce at puremagic.com
Thu Feb 2 09:44:13 PST 2017


On 02/02/2017 07:10 AM, aberba wrote:
>
> * Moreover, how do I close a connection or does it auto close?
>

It closes in its destructor (although AIUI there are times when dtors 
don't get run). But it can be closed manually with Connection.close();

> * Does it support mysql_real_escape_string() like in php? This factor-in
> the db encoding to do he appriate encoding for '/\" ...

There is a function like that one that was contributed, 
mysql.escape.mysql_escape:

https://github.com/Abscissa/mysql-native-experimental/blob/master/source/mysql/escape.d#L4

But, it's better to use prepared statements, because then no escaping is 
needed, and there's no worry about forgetting to escape:

Prepared prepared = prepare(connection, "SELECT * FROM `someTable` WHERE 
i=? AND s=?");
prepared.setArgs(7, "hello");
ResultRange results = prepared.query();

The prepared statement is reference counted and will automatically be 
released when there are no references to it left.



More information about the Digitalmars-d-announce mailing list