It select a MySQL database
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
mysql_select_db(“database_name”);
echo mysql_result(mysql_query( “SELECT * FROM users”),1);
mysql_close();
?>
Output
2
It returns the value of a field in a recordset
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_result(mysql_query( “SELECT * FROM users”),1);
mysql_close();
?>
Output
2
Escapes a string for use in SQL statements
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_rows(mysql_query( “SELECT * FROM users WHERE name='”.mysql_real_escape_string(“PHP”).”‘”));
mysql_close();
?>
Output
1
It executes a query on a MySQL database
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_rows(mysql_query( “SELECT * FROM users”));
mysql_close();
?>
Output
5
Ping a server connection or reconnect if there is no connection
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
mysql_ping();
echo mysql_num_rows(mysql_query( “SELECT * FROM users”));
mysql_close();
?>
Output
5
It opens a persistent MySQL connection
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | ASP |
| 3 | JSP |
| 4 | JS |
| 5 | AS |
+—-+——+
Example
<?php
mysql_pconnect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_rows(mysql_query( “SELECT * FROM users”));
mysql_close();
?>
Output
5
It returns number of rows in result
MySQL Table – Users
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | PHP |
| 3 | PHP |
| 4 | PHP |
| 5 | PHP |
Example
<?php
mysql_connect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_rows(mysql_query( “SELECT * FROM users”));
mysql_close();
?>
Output
5
It returns number of fields in result
MySQL Table
+—-+——+
| id | name |
+—-+——+
| 1 | PHP |
| 2 | PHP |
| 3 | PHP |
| 4 | PHP |
| 5 | PHP |
Example
<?php
mysql_connect(“localhost”, “root”, “phpcode”) or die(mysql_error());
$db_selected = mysql_select_db(“database_name”);
echo mysql_num_fields(mysql_query( “SELECT * FROM users”));
mysql_close();
?>
Output
2
It lists tables in a MySQL database . Its deprecated
Example
<?php
$conn=mysql_connect(“localhost”, “root”, “phpcode”) or die( mysql_error());
$table = mysql_list_tables (“database_name”);
for ($i=0; $i < mysql_num_rows($table); ++$i) {
echo mysql_result ($table, $i, 0), ‘<br />’;
}
?>
Output
users
It lists MySQL processes
Example
<?php
$conn=mysql_connect(“localhost”, “root”, “phpcode”) or die( mysql_error());
echo “<pre>”;
$process= mysql_list_processes($conn);
while ($row = mysql_fetch_assoc($process)) {
print_r($row);
}
?>
Output
Array
(
[Id] => 1061
[User] => root
[Host] => localhost
[db] =>
[Command] => Processlist
[Time] => 0
[State] =>
[Info] =>
)
Posts navigation
Zend | Magento Certified PHP | eCommerce Architect