PHP MySQL Functions
#1

PHP MySQL Functions+


Definition and Usage
The mysql_connect() function opens a non-persistent MySQL connection.
This function returns the connection on success, or FALSE and an error on failure. You can hide the error output by adding an '@' in front of the function name.


Definition and Usage
The mysql_error() function returns the error description of the last MySQL operation.
This function returns an empty string ("") if no error occurs.
Syntax
mysql_error(connection)

Parameter Description
connection Optional. Specifies the MySQL connection. If not specified, the last connection opened by mysql_connect() or mysql_pconnect() is used.

________________________________________
Example
In this example we will try to log on to a MySQL server with the wrong username and password:
<?php
$con = mysql_connect("localhost","wrong_user","wrong_pwd");
if (!$con)
{
die(mysql_error());
}
mysql_close($con);
?>
The output of the code above could be:
Access denied for user 'wrong_user'@'localhost'
(using password: YES)

PHP mysql_fetch_array() Function
________________________________________
Complete PHP MySQL Reference
________________________________________
Definition and Usage
The mysql_fetch_array() function returns a row from a recordset as an associative array and/or a numeric array.
This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.
Syntax
mysql_fetch_array(data,array_type)

Parameter Description
data Required. Specifies which data pointer to use. The data pointer is the result from the mysql_query() function
array_type Optional. Specifies what kind of array to return.
Possible values:
• MYSQL_ASSOC - Associative array
• MYSQL_NUM - Numeric array
• MYSQL_BOTH - Default. Both associative and numeric array

________________________________________
Tips and Notes
Note: After the data is retrieved, this function moves to the next row in the recordset. Each subsequent call to mysql_fetch_array() returns the next row in the recordset.
Tip: Field names returned by this function are case-sensitive.
________________________________________
Example
<?php
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person WHERE Lastname='Refsnes'";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_array($result));

mysql_close($con);
?>
The output of the code above could be:
Array
(
[0] => Refsnes
[LastName] => Refsnes
[1] => Kai Jim
[FirstName] => Kai Jim
[2] => Taugata 2
[Address] => Taugata 2
[3] => 22
[Age] => 22
)

PHP mysql_fetch_row() Function
________________________________________
Complete PHP MySQL Reference
________________________________________
Definition and Usage
The mysql_fetch_row() function returns a row from a recordset as a numeric array.
This function gets a row from the mysql_query() function and returns an array on success, or FALSE on failure or when there are no more rows.
Syntax
mysql_fetch_row(data)

Parameter Description
data Required. Specifies which data pointer to use. The data pointer is the result from the mysql_query() function

________________________________________
Tips and Notes
Note: After the data is retrieved, this function moves to the next row in the recordset. Each subsequent call to mysql_fetch_assoc() returns the next row in the recordset.
________________________________________
Example
<?php
$con = mysql_connect("localhost", "peter", "abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person WHERE Lastname='Refsnes'";
$result = mysql_query($sql,$con);
print_r(mysql_fetch_row($result));

mysql_close($con);
?>
The output of the code above could be:
Array
(
[0] => Refsnes
[1] => Kai Jim
[2] => Taugata 2
[3] => 22
)

PHP mysql_query() Function
________________________________________
Complete PHP MySQL Reference
________________________________________
Definition and Usage
The mysql_query() function executes a query on a MySQL database.
This function returns the query handle for SELECT queries, TRUE/FALSE for other queries, or FALSE on failure.
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: jim fazio, php mysql interview questions for 2, php and mysql, php mysql seminar topic, espn jim harbaugh, jim fazio**ngstan today com**t banking system, seminar topics about mysql,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  Basic Principles and Functions of Electrical Machines seminar addict 1 1,837 12-11-2012, 01:27 PM
Last Post: seminar details
  Types and Functions of Jigs and Fixtures project uploader 1 3,236 27-10-2012, 04:11 PM
Last Post: seminar details
  FUNCTIONS OF ORGANIC MATTER IN SOIL seminar paper 0 1,117 15-03-2012, 01:02 PM
Last Post: seminar paper
  Address Conversion Functions and The Domain Name System ppt seminar paper 0 904 06-03-2012, 03:26 PM
Last Post: seminar paper
  PHP-Mysql Form Builder seminar topics 3 2,755 29-02-2012, 09:38 AM
Last Post: seminar paper
  PHP TECHNOLOGY seminar addict 0 684 18-01-2012, 03:18 PM
Last Post: seminar addict
  The History of PHP project report helper 1 1,465 29-10-2010, 02:32 PM
Last Post: project report helper
  Building a Database-Driven Web Site Using PHP and MySQL project report helper 0 1,311 19-10-2010, 03:16 PM
Last Post: project report helper

Forum Jump: