PHP » PYTHON |
login |
register |
about
|
PYTHON mysql_query
is this article helpful?
|
Python replacement for PHP's mysql_query
[
edit
| history
]
MySQLdb - execute()
cursor.execute(query) Example 1 - SELECT import MySQLdb dbcon = MySQLdb.connect(host="127.0.0.1", user="dbuser", passwd="dbpass" db="mydatabase") dbcur = dbcon.cursor() qry = "SELECT * FROM mytable" dbcur.execute(qry) results = dbcur.fetchall() dbcon.close() Example 2 - INSERT import MySQLdb dbcon = MySQLdb.connect(host="127.0.0.1", user="dbuser", passwd="dbpass" db="mydatabase") dbcur = dbcon.cursor() qry = "INSERT INTO mytable VALUES(NULL, NOW(), 'hello', 'world')" dbcur.execute(qry) dbcon.close() mysql_query(PHP 4, PHP 5) mysql_query — Send a MySQL query Description
resource mysql_query
( string $query
[, resource $link_identifier
] )
mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier . Parameters
Return ValuesFor SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. The returned result resource should be passed to mysql_fetch_array(), and other functions for dealing with result tables, to access the returned data. Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement. mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query. Examples
Example #1 Invalid Query The following query is syntactically invalid, so mysql_query() fails and returns FALSE.
<?php
Example #2 Valid Query The following query is valid, so mysql_query() returns a resource.
<?php
See Also
|
more
Recently updated
more
Most requested
more
Last requests
|