Home

Andrey a écrit :
> Hi
>
> just a quick question about using MySQL module... are there any api / class
> available to give a higher level in working with Mysql in python?
> such as
> db.fetch_array(),
> db.fetch_rows(),
> db.query(),
> for eachrow in db.fetch_array():
> xxxx

You really find this "higher level" than Python's db-api ???

> just as easy as PHP?

D'oh :(


// PHP:
// suppose we have a valid $connection
$q = mysql_query("select * from yaddayadda", $connection)
if (is_resource($q)) {
while($row = mysql_fetc_row($q)) {
do_something_with($row);
}
mysql_free($q);
}
else {
// handle the error here
}

# python:
# suppose we have a valid connection
cursor = connection.cursor() # can specify the kind of cursor here
try:
cursor.execute("select * from yaddayadda")
except MysqlError, e:
# handle error here
else:
for row in cursor:
do_something_with(row)

# not strictly necessary, you can reuse the same
# cursor for another query
cursor.close()


As far as I'm concerned, I fail to see how PHP is "higher level" or
"easier" here.

previous
next

Re: number of digits in a number
Re: stdout and embedding into Windows apps
Re: Performance monitoring tools.
Re: The least used keywords in C++, which do you use?
Re: Question about objects
airsoft
poker
piece kaflowe
bwin
unibet.com