PHP mysql_query() ਫੰਕਸ਼ਨ
ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ
mysql_query() ਫੰਕਸ਼ਨ ਇੱਕ MySQL ਕਿਸਮ ਨੂੰ ਚਲਾਉਂਦਾ ਹੈ。
ਸਿਫਾਰਸ਼
mysql_query(query,connection)
ਪੈਰਾਮੀਟਰ | ਵਰਣਨ |
---|---|
query | ਲਾਜ਼ਮੀ। ਜੋ ਕਿ ਭੇਜਣ ਯੋਗ ਐੱਸਕਿਊਐਲ ਕਿਸਮ ਨੂੰ ਨਿਰਦੇਸ਼ਿਤ ਕਰਦਾ ਹੈ। ਟਿੱਪਣੀ: ਕਿਸਮ ਵਾਕ ਨੂੰ ਪੁਨਰਮੁੱਢਕਰਨ ਨਾ ਕਰਨਾ ਚਾਹੀਦਾ ਹੈ。 |
connection | ਵਿਕਲਪੀ। ਐੱਸਕਿਊਐਲ ਕਨੈਕਸ਼ਨ ਪਹਿਚਾਣ ਦੀ ਨਿਰਦੇਸ਼ਣ। ਜੇਕਰ ਇਹ ਨਾ ਦਿੱਤਾ ਗਿਆ ਹੈ ਤਾਂ ਪਿਛਲੀ ਖੁੱਲ੍ਹੀ ਕਨੈਕਸ਼ਨ ਦਾ ਉਪਯੋਗ ਕੀਤਾ ਜਾਵੇਗਾ。 |
ਵਿਵਰਣ
ਜੇਕਰ ਕੋਈ ਖੁੱਲ੍ਹੀ ਕਨੈਕਸ਼ਨ ਨਹੀਂ ਹੈ ਤਾਂ ਇਹ ਫੰਕਸ਼ਨ mysql_connect() ਫੰਕਸ਼ਨ ਦਾ ਬੇਪਾਰਮੀ ਸਿਫਾਰਸ਼ ਕਰਦਾ ਹੈ ਤਾਂ ਕਿ ਇੱਕ ਨਵੀਂ ਕਨੈਕਸ਼ਨ ਬਣਾਈ ਜਾ ਸਕੇ ਅਤੇ ਉਸ ਦਾ ਉਪਯੋਗ ਕੀਤਾ ਜਾ ਸਕੇ。
ਵਾਪਸ ਦਿੱਤਾ ਗਿਆ ਮੁੱਲ
mysql_query() ਕੇਵਲ SELECT،SHOW،EXPLAIN ਜਾਂ DESCRIBE ਵਾਕਯਾਂ ਨੂੰ ਇੱਕ ਸੰਸਾਧਨ ਪਹਿਚਾਣ ਵਾਪਸ ਦਿੰਦਾ ਹੈ، ਜੇਕਰ ਕਿਸੇ ਕਿਸਮ ਦਾ ਕੁਸ਼ਲਤਾ ਨਹੀਂ ਹੁੰਦਾ ਤਾਂ FALSE ਵਾਪਸ ਦਿੰਦਾ ਹੈ。
For other types of SQL statements, mysql_query() returns TRUE on successful execution and FALSE on error.
A non FALSE return value means that the query is valid and can be executed by the server. This does not mean anything about the number of rows affected or returned. It is very likely that a query has been executed successfully but has not affected or returned any rows.
Tips and comments
Note:This function automatically reads and caches the record set. To run a non-cached query, please use mysql_unbuffered_query().
Instance
Example 1
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } $sql = "SELECT * FROM Person"; mysql_query($sql,$con); // Some code mysql_close($con); ?>
Example 2
Through mysql_query() function create a new database:
<?php $con = mysql_connect("localhost","mysql_user","mysql_pwd"); if (!$con) { die('Could not connect: ' . mysql_error()); } $sql = "CREATE DATABASE my_db"; if (mysql_query($sql,$con)) { echo "Database my_db created"; } else { echo "Error creating database: " . mysql_error(); } ?>