MySQL database functions detailed (2)

Source: Internet
Author: User
Tags continue error code connect printf mysql database
mysql| Function | data | database | detailed 5 int mysql_data_seek (int result_id, int row_num);

Each result set returned by the Select query has a row cursor that indicates which row the next function (Mysql_fetch_array (), mysql_fetch_object (), or mysql_fetch_row ()) calls will return. Mysql_data_seek () Sets the pointer for the given result set to the given row. Line numbers range from 0 to mysql_num_rows ()-1. If the line number is valid, Mysql_data_seek () returns True, otherwise the return is false.
<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
mysql_select_db ("samp_db") or Die ("could not select Database");
$query = "Select Last_name,first_name from President");
$result =mysql_query ($query) or Die ("Query failed");
For ($i =mysql_num_rows ($result)-1; $i >=0; $i-)
{
if (!mysql_data_seek ($result, $i);
{
printf ("Cannot seek to row%dn", $i);
Continue
}
if (! $row =mysql_fetch_object ($result)))
Continue
printf ("%d%s<br>n", $row->last_name, $row->first_name);
}
Mysql_free_result ($result);
?>


(6) Int mysql_db_query (string db_name, string query [, int link_id]);
Mysql_db_query () is similar to mysql_query () in addition to extracting an additional database name parameter and making it the default database before executing the query.

<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
Print ("Connected successfully");
$query = "SELECT * from President";
$result =mysql_db_query ("samp_db", $query) or Die ("Query failed");
?>


(7) int mysql_drop_db (string db_name, int [link_id]);
Tells the MySQL server identified by link_id to delete the database with the given name. Returns true if the database deletion is successful, or False if an error occurs. You must have drop permissions on the database for deletion.
Be careful with this function; If you delete the database, it does not exist and cannot be recovered.
Using mysql_query () is more appropriate than using mysql_drop_db () to publish a drop DATABASE statement.
<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
if (mysql_drop_db ("my_db"))
Print ("Database dropped Successfullyn");
Else
printf ("Error dropping Database:%sn", mysql_error ());
?>


(8) int mysql_errno (int [link_id]);

For a given connection, returns the error number of the MySQL-related function that contains the most recent return status. A value of 0 means that no error has occurred.

Usage examples

<?php
$link =mysql_pconnect ("localhost", "Sunsoft", "Suixiang") or Die ("could not Connect");
Print ("Connected successfully");
$query = "SELECT * from President";
$result =mysql_query ($query) or Die ("Query Failed,error code=". Mysql_errno ());
?>



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.