bidvertiser

Tuesday, February 24, 2009

I LOVE CHINA

This Blog is dedicated to China's People because I Love China and thier peoples....                                                                                                                                                                                                                                                                                  From: Ozair khan                                                                                                                                                 mrozairkhan@yahoo.com                                                                                                                                 Pakistan

Sunday, January 11, 2009

What is PHP?

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. If you are new to PHP and want to get some idea of how it works. After that, check out the online manual, and the example archive sites and some of the other resources available in the links secton.


Wednesday, October 22, 2008

Querying data from a table code

// Make a MySQL Connection
mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

// Retrieve all the data from the "example" table
$result = mysql_query("SELECT * FROM example")
or die(mysql_error());

// store the record of the "example" table into $row
$row = mysql_fetch_array( $result );
// Print out the contents of the entry

echo "Name: ".$row['name'];
echo " Age: ".$row['age'];

?>

Inserting data into a table code

mysql_connect("localhost", "admin", "1admin") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());
// Insert a row of information into the table "example"
mysql_query("INSERT INTO example (name, age)
VALUES('Timmy Mellowman', '23' ) ") or die(mysql_error());
mysql_query("INSERT INTO example (name, age)
VALUES('Sandy Smith', '21' ) ") or die(mysql_error());
mysql_query("INSERT INTO example (name, age)
VALUES('Bobby Wallace', '15' ) ") or die(mysql_error());
echo "Data Inserted!";
?>

MySQL Function Reference example code

if (!$link)
{ die('Could not connect: ' . mysql_error());
} mysql_select_db('mydb'); /* Update records */
mysql_query("UPDATE mytable SET used=1 WHERE id < 10");
printf ("Updated records: %d\n", mysql_affected_rows());
mysql_query("COMMIT");
?>

MySQL Function Reference example code

if (!$link)
{
die('Could not connect: ' . mysql_error());
} mysql_select_db('mydb'); /* this should return the correct numbers of deleted records */ mysql_query('DELETE FROM mytable WHERE id < 10');
printf("Records deleted: %d\n", mysql_affected_rows());
/* with a where clause that is never true, it should return 0 */ mysql_query('DELETE FROM mytable WHERE 0');
printf("Records deleted: %d\n", mysql_affected_rows());
?>

MySQL Function Reference contd..

int mysql_affected_rows ([ resource $link_identifier ] )
Gets the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with link_identifier.
Return Values
Returns the number of affected rows on success, and -1 if the last query failed.
If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2.
When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows() may not actually equal the number of rows matched, only the number of rows that were literally affected by the query.
The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records.

MySQL Function Reference example code

mysql_select_db("database", $link);
$result = mysql_query("SELECT * FROM table1", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
?>

$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
/* returns 2 because id,email === two fields */
echo mysql_num_fields($result);
?>

MySQL Function Reference contd..

int mysql_num_rows ( resource $result )
Retrieves the number of rows from a result set. This command is only valid for statements like SELECT or SHOW that return an actual result set. To retrieve the number of rows affected by a INSERT, UPDATE, REPLACE or DELETE query, use mysql_affected_rows().
$result.
The result resource that is being evaluated.
Return value.
The number of rows in a result set on success, or FALSE on failure.

int mysql_num_fields ( resource $result )
Retrieves the number of fields from a query.
Returns the number of fields in the result set resource on success, or FALSE on failure.

MySQL Function Reference contd..

resource mysql_db_query ( string $database , string $query [, resource $link_id] ) .
Selects a database, and executes a query on it.
$database
The name of the database that will be selected.
$query
The MySQL query.
Return value.
Returns a positive MySQL result resource to the query result, or FALSE on error.

MySQL Function Reference example code

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) 
{ die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

MySQL Function Reference contd..

string mysql_error ([ resource $link_identifier ] )
Returns the error text from the last MySQL function. Errors coming back from the MySQL database backend no longer issue warnings. Instead, use mysql_error() to retrieve the error text. Note that this function only returns the error text from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function.
$link_identifier.
The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
Return value.
Returns the error text from the last MySQL function, or '' (empty string) if no error occurred.

int mysql_errno ([ resource $link_identifier ] )
Returns the error number from the last MySQL function or 0 (zero) if no error occurred.
bool mysql_close ([ resource $link_identifier ] )
closes the non-persistent connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
Return value.
Returns TRUE on success or FALSE on failure.